1

I have the following file

 more  file.txt

 1 2 3 4 4 2
 23 4 5 23 2 3
 END_OF_LINE
 1 3 7 4 2 
 23 4 6 7 4 2 1 5 

How to print only the fields 4 and 5 and 6 until the line END_OF_LINE , and from the line END_OF_LINE until the end of file , the same lines ( all the fields )

Meanwhile I have only partial solution

 awk '{print $4" "$5" "$6}'  

Example: of the requested output

awk syntax ..... file.txt

 4 4 2
 23 2 3
 END_OF_LINE
 1 3 7 4 2 
 23 4 6 7 4 2 1 5 

migrated from stackoverflow.com Dec 29 '13 at 8:15

This question came from our site for professional and enthusiast programmers.

3

Same idea as Ed Morton's answer just slightly different awk feature use:

awk '/END_OF_LINE/ {f=1}; f; !f {print $4, $5, $6}' file.txt
3
awk '/END_OF_LINE/{f=1} {print (f ? $0 : $4, $5, $6)}' file
1

Using sed

sed '0,/END_OF_LINE/ s/[^ ]* [^ ]* [^ ]* //' file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy