How to get info from a file with sed/awk/perl 
Author Message
 How to get info from a file with sed/awk/perl

Sorry if this a basic questionand, of course, the cross post.   I need to process a text file containing statistics in the next way:
1)find the lines where appear the string 4[0-9][0-9][0-9] and after the 4 digits a blank space
2) once we find such line, join the previous line with the curren and the next.

Example

aaaa aaaaaa aaaa
bbbbbb bbbbbbb bbbbbbb
4325 ccccc cccccc
ddddd dddd ddd
eeee eeeeeeeee eeee

The result:

bbbbbb bbbbbbb bbbbbbb 4325 ccccc cccccc ddddd dddd ddd

Thanks



Sun, 25 Nov 2001 03:00:00 GMT  
 How to get info from a file with sed/awk/perl

Quote:

>This is a multi-part message in MIME format.

Generally, a mistake on the Usenet.

Quote:
>Sorry if this a basic questionand, of course, the cross post.   I need =
>to process a text file containing statistics in the next way:=20
>1)find the lines where appear the string 4[0-9][0-9][0-9] and after the =
>4 digits a blank space
>2) once we find such line, join the previous line with the curren and =
>the next.

>Example

>aaaa aaaaaa aaaa
>bbbbbb bbbbbbb bbbbbbb
>4325 ccccc cccccc
>ddddd dddd ddd
>eeee eeeeeeeee eeee

>The result:

>bbbbbb bbbbbbb bbbbbbb 4325 ccccc cccccc ddddd dddd ddd

The general idiom is:

        /^4[0-9][0-9][0-9]/ { getline Next ; print Prev,$0,Next }
        { Prev = $0 }

Quote:
>Thanks

Hope it helps...

55 lines of {*filter*}that doesn't belong on the Usenet - mercifully deleted.



Sun, 25 Nov 2001 03:00:00 GMT  
 How to get info from a file with sed/awk/perl
On Wed, 9 Jun 1999 14:58:24 -0400,

Quote:

>Sorry if this a basic questionand, of course, the cross post. I need to
>process a text file containing statistics in the next way: 1)find the
>lines where appear the string 4[0-9][0-9][0-9] and after the 4 digits a
>blank space 2) once we find such line, join the previous line with the
>curren and the next.

sed -n '/4[0-9][0-9][0-9] /{
          H;n;x;G;s/\n/ /gp;b
        }
        h'

(I originally wrote the line starting "H;n" as the simpler:
          x;G;N;s/\n/ /gp
but that won't work quite right if there are not at least
two lines between each match of the /4.../ pattern.  As it
sits, I'm not sure if it does the right thing if there are
back-to-back lines which match, as that situation is
inadeqautely defined in the problem statement.)

                --Ken Pizzini



Mon, 26 Nov 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Getting awk (or sed or anything else) to put single quotes into file

2. Outputting info from awk and using the info to name the awk output file

3. sed, awk, perl

4. extracting top 100 data using awk or sed/perl

5. Perl versus sed + awk + ksh

6. Awk and Sed info. wanted

7. log file processing - awk or sed

8. Using awk And/Or sed To Edit Fourth Field Of File

9. deleting records in a file using AWK, SED, or kshell

10. sed/awk script to format a file??

11. Tcl as a replacement for perl/sed command line work

12. Getting Field Info from a file..

 

 
Powered by phpBB® Forum Software