sed for finding and merging

August 13, 2010 at 07:42:48
Specs: linux
hi,
I have the following lines:
9 36 52.039000  2.325875 -111 -10 -313
9 36 52.065000  2.351875 -111 -10 -308
-------------------MARK 0------------------
63449775412.206

9 36 52.221000  2.507875 -106 -15 -308
9 36 52.247000  2.533875 -111 -15 -313
9 36 52.273000  2.559875 -122 -10 -308
-------------------MARK 1------------------
63449775417.8061

9 36 57.813125  8.100000 -117 -10 -303
9 36 57.837125  8.124000 -111 -15 -303
9 36 57.863125  8.150000 -111 -15 -308
9 36 57.889125  8.176000 -117 -15 -308
9 36 57.915125  8.202000 -111 -10 -308
9 36 57.941125  8.228000 -117 -10 -308

Could I use sed command to do the following:
1. find line that contains 'MARK'
2. merge that line with the next two

Thank you in advance.


See More: sed for finding and merging

Report •

#1
August 13, 2010 at 18:41:02
Implementing condtionals in sed is not easy. How about an awk script:

#!/bin/bash

awk ' {
   if(match($0, "MARK") > 0)
      {
      printf("%s", $0)
      getline
      printf("%s", $0)
      getline
      printf("%s\n", $0)
      }
      printf("%s\n", $0)

} ' datafile.txt


Report •

#2
August 16, 2010 at 08:11:01
sed '/MARK/{N;s/\n//;N;s/\n//}' file

GNU win32 packages | Gawk


Report •
Related Solutions


Ask Question