Find the answer to your Linux question:
Results 1 to 4 of 4
hi can any one help me out.. my row.txt file contains like this...i want to get the first field of row1 row2 and so on.. [Row] 1 1 2.940769361E-009 2 ...
  1. #1
    Just Joined!
    Join Date
    Jan 2009
    Posts
    12

    pattern match

    hi can any one help me out..

    my row.txt file contains like this...i want to get the first field of row1 row2 and so on..

    [Row] 1
    1 2.940769361E-009
    2 2.430446475E-011
    3 2.476075468E-011

    [Row] 2
    2 1.327840827E-009
    3 4.387348541E-010
    4 1.161288314E-010
    5 1.7906279E-010
    6 1.231085385E-010
    [Row] 3
    3 1.07825276E-009
    4 1.219313865E-010
    5 1.151911893E-010

    expected output:
    1 2.940769361E-009
    2 1.327840827E-009
    3 1.07825276E-009

    need urgently and the o/p to be directed to a new file

  2. #2
    Linux Newbie radoulov's Avatar
    Join Date
    Sep 2007
    Posts
    111
    Code:
    awk '_&&_--;/^\[/{_=1}' infile
    The redirection is easy

  3. #3
    Just Joined!
    Join Date
    Jan 2009
    Posts
    12

    thnx

    hey thnx a lot...
    but can u please explain me the code,so that next time i can do it of my own..

  4. #4
    Linux Newbie radoulov's Avatar
    Join Date
    Sep 2007
    Posts
    111
    Code:
    /^\[/{_=1}
    If the current record matches the the pattern - [ at the beginning of the string - assign the value 1 (i.e. true in boolean context) to the variable _.

    Code:
    _&&_--
    Decrement the _ variable while it returns true evaluated in boolean context triggering the default action (which is print the current record).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...