Edit column using sort

Hi Expert,

Please kindly need your help, I dont have any idea how to make this input to be as output.

Thanks before

[paradigm@lemahabang EB]$ more input.dat
@zmap_fault HEADER                 ,      FALT,      80,       1
 X (EASTING)         , 1, 1, 1,  1, 15, 7,  0.1000000E+31,            , 15, 7, 0
 Y (NORTHING)        , 2, 2, 1, 16, 30, 7,  0.1000000E+31,            , 15, 7, 0
 Z - FIELD           , 3, 3, 1, 31, 45, 7,  0.1000000E+31,            , 15, 7, 0
 SEG I.D.            , 4,35, 1, 46, 60, 7,  0.1000000E+31,            , 15, 7, 0
@
       784788.9       104383.1       0.000000       1.000000
       784788.9       86665.28       0.000000       1.000000
       784788.9       68947.42       0.000000       1.000000
       768194.8       68947.42       0.000000       1.000000
       751600.7       68947.42       0.000000       1.000000
       751600.7       86665.28       0.000000       1.000000
       751600.7       104383.1       0.000000       1.000000
       768194.8       104383.1       0.000000       1.000000
       784788.9       104383.1       0.000000       1.000000
       755547.9       95036.69       0.000000       2.000000
       755545.7       95010.64       0.000000       2.000000
       755538.9       94985.38       0.000000       2.000000
       755527.8       94961.69       0.000000       2.000000
       755512.9       94940.27       0.000000       2.000000
       755494.4       94921.78       0.000000       2.000000
       755472.9       94906.78       0.000000       2.000000
       755449.2       94895.73       0.000000       2.000000
       755424.0       94888.97       0.000000       2.000000
       755397.9       94886.69       0.000000       2.000000
       755371.9       94888.97       0.000000       2.000000
       755346.6       94895.73       0.000000       2.000000
       755322.9       94906.78       0.000000       2.000000
       755301.5       94921.78       0.000000       2.000000
       755283.0       94940.27       0.000000       2.000000
       755268.1       94961.69       0.000000       2.000000
       755257.0       94985.38       0.000000       2.000000
       755250.2       95010.64       0.000000       2.000000
       755247.9       95036.69       0.000000       2.000000
       755250.2       95062.73       0.000000       2.000000
       755257.0       95087.99       0.000000       2.000000
       755268.1       95111.69       0.000000       2.000000
       755283.0       95133.11       0.000000       2.000000
       755301.5       95151.59       0.000000       2.000000
       755322.9       95166.59       0.000000       2.000000
       755346.6       95177.64       0.000000       2.000000
       755371.9       95184.41       0.000000       2.000000
       755397.9       95186.69       0.000000       2.000000
       755424.0       95184.41       0.000000       2.000000
       755449.2       95177.64       0.000000       2.000000
       755472.9       95166.59       0.000000       2.000000
       755494.4       95151.59       0.000000       2.000000
       755512.9       95133.11       0.000000       2.000000
       755527.8       95111.69       0.000000       2.000000
       755538.9       95087.99       0.000000       2.000000
       755545.7       95062.73       0.000000       2.000000
       755547.9       95036.69       0.000000       2.000000
       755546.8       93139.06       0.000000       3.000000
       755544.6       93113.02       0.000000       3.000000
       755537.8       93087.76       0.000000       3.000000
       755526.7       93064.06       0.000000       3.000000
       755511.8       93042.64       0.000000       3.000000
       755493.2       93024.16       0.000000       3.000000
       755471.8       93009.16       0.000000       3.000000
       755448.1       92998.11       0.000000       3.000000
       755422.9       92991.34       0.000000       3.000000
       755396.8       92989.06       0.000000       3.000000
       755370.8       92991.34       0.000000       3.000000
       755345.5       92998.11       0.000000       3.000000
       755321.8       93009.16       0.000000       3.000000
       755300.4       93024.16       0.000000       3.000000
       755281.9       93042.64       0.000000       3.000000
       755266.9       93064.06       0.000000       3.000000
       755255.9       93087.76       0.000000       3.000000
       755249.1       93113.02       0.000000       3.000000
       755246.8       93139.06       0.000000       3.000000
       755249.1       93165.11       0.000000       3.000000
       755255.9       93190.37       0.000000       3.000000
       755266.9       93214.06       0.000000       3.000000
       755281.9       93235.48       0.000000       3.000000
       755300.4       93253.97       0.000000       3.000000
       755321.8       93268.97       0.000000       3.000000
       755345.5       93280.02       0.000000       3.000000
       755370.8       93286.78       0.000000       3.000000
       755396.8       93289.06       0.000000       3.000000
       755422.9       93286.78       0.000000       3.000000
       755448.1       93280.02       0.000000       3.000000
       755471.8       93268.97       0.000000       3.000000
       755493.2       93253.97       0.000000       3.000000
       755511.8       93235.48       0.000000       3.000000
       755526.7       93214.06       0.000000       3.000000
       755537.8       93190.37       0.000000       3.000000
       755544.6       93165.11       0.000000       3.000000
       755546.8       93139.06       0.000000       3.000000

and output as below

[paradigm@lemahabang EB]$   more output.dat
Cartograpic data in user defined format
....V....1....V....2....V....3....V....4....V....5....V....6....V....7
p input_file_name
       784788.9       104383.1
       784788.9       86665.28
       784788.9       68947.42
       768194.8       68947.42
       751600.7       68947.42
       751600.7       86665.28
       751600.7       104383.1
       768194.8       104383.1
       784788.9       104383.1
99999
p input_file_name
       755547.9       95036.69
       755545.7       95010.64
       755538.9       94985.38
       755527.8       94961.69
       755512.9       94940.27
       755494.4       94921.78
       755472.9       94906.78
       755449.2       94895.73
       755424.0       94888.97
       755397.9       94886.69
       755371.9       94888.97
       755346.6       94895.73
       755322.9       94906.78
       755301.5       94921.78
       755283.0       94940.27
       755268.1       94961.69
       755257.0       94985.38
       755250.2       95010.64
       755247.9       95036.69
       755250.2       95062.73
       755257.0       95087.99
       755268.1       95111.69
       755283.0       95133.11
       755301.5       95151.59
       755322.9       95166.59
       755346.6       95177.64
       755371.9       95184.41
       755397.9       95186.69
       755424.0       95184.41
       755449.2       95177.64
       755472.9       95166.59
       755494.4       95151.59
       755512.9       95133.11
       755527.8       95111.69
       755538.9       95087.99
       755545.7       95062.73
       755547.9       95036.69
99999
p input_file_name
       755546.8       93139.06
       755544.6       93113.02
       755537.8       93087.76
       755526.7       93064.06
       755511.8       93042.64
       755493.2       93024.16
       755471.8       93009.16
       755448.1       92998.11
       755422.9       92991.34
       755396.8       92989.06
       755370.8       92991.34
       755345.5       92998.11
       755321.8       93009.16
       755300.4       93024.16
       755281.9       93042.64
       755266.9       93064.06
       755255.9       93087.76
       755249.1       93113.02
       755246.8       93139.06
       755249.1       93165.11
       755255.9       93190.37
       755266.9       93214.06
       755281.9       93235.48
       755300.4       93253.97
       755321.8       93268.97
       755345.5       93280.02
       755370.8       93286.78
       755396.8       93289.06
       755422.9       93286.78
       755448.1       93280.02
       755471.8       93268.97
       755493.2       93253.97
       755511.8       93235.48
       755526.7       93214.06
       755537.8       93190.37
       755544.6       93165.11
       755546.8       93139.06
99999

I don't have either. Pls be more specific on how to translate / transfer your input data to the desired output, what criteria apply when, etc.

this is using field 4 as controller. if the number in field 4 are same, we take field 1 and field 2.
And if if the number in field 4 are same, they have same header. (begining by "p input_file_name" and ending by 99999.

thank and regards

Try

awk     'BEGIN          {print "whatever header you want"}
         NR  < 7        {next}
         NR == 7        {fl=$4; print "p input_file_name"}
         fl != $4       {print "99999\np input_file_name"; fl = $4}
                        {print x, $1, $2}
         END            {print "99999"}
        ' OFS="\t" file
whatever header you want
p input_file_name
    784788.9    104383.1
    784788.9    86665.28
.
.
.
    784788.9    104383.1
99999
p input_file_name
    755547.9    95036.69
.
.
.

Nearly the same as I created, but yours more clean :slight_smile:

awk 'BEGIN {print "Cartograpic data in user defined format";
print "....V....1....V....2....V....3....V....4....V....5....V....6....V....7"}
$1~"^[0-9]" && b==0 {print "p input_file_name\n\t"$1"\t"$2; p=$4;b=1;next}
$1~"^[0-9]" && p==$4 {print "\t"$1"\t"$2}
$1~"^[0-9]" && p!=$4 {print "99999\np input_file_name\n\t"$1"\t"$2; p=$4}
END {print "99999"}' filename

thank Experts...