Edit column using sort


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Edit column using sort
# 1  
Old 02-15-2013
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

Code:
[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
Code:
[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

# 2  
Old 02-15-2013
Quote:
Originally Posted by ipatah
Hi Expert,
Please kindly need your help, I dont have any idea how to make this input to be as output.
Thanks before
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.
# 3  
Old 02-15-2013
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
# 4  
Old 02-15-2013
Try
Code:
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
.
.
.

# 5  
Old 02-15-2013
Nearly the same as I created, but yours more clean Smilie
Code:
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

# 6  
Old 02-18-2013
thank Experts...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Use sort to sort numerical column

How to sort the following output based on lowest to highest BE? The following sort does not work. $ sort -t. -k1,1n -k2,2n bfd.txt BE31.116 0s 0s DOWN DAMP BE31.116 0s 0s DOWN DAMP BE31.117 0s 0s ... (7 Replies)
Discussion started by: sand1234
7 Replies

2. Shell Programming and Scripting

Need Help to Edit multiple column of a file

Hello Team, I want to know if there is any one liner command , using which I can edit multiple column of a file. input file input.txt (comma separated), taran, 12.45, uttam, 23.40, babay karan, 12.45, raju, 11.40, rahulg I want to update, 2nd and 4th column, but want all those column... (8 Replies)
Discussion started by: Uttam Maji
8 Replies

3. UNIX for Dummies Questions & Answers

Sort command in one column and not effect to another column

If my data is numerical : 1 = 101 2 = 102 3 = 104 4 = 104 7 = 103 8 = 103 9 = 105 I need the result like below: 1 = 101 2 = 102 3 = 103 4 = 103 7 = 104 8 = 104 9 = 105 (4 Replies)
Discussion started by: GeodusT
4 Replies

4. UNIX for Dummies Questions & Answers

Sort on one column only

Hello, I am running on AIX.I have a question about sorting in UNIX. if my file is something like this: a c b d a b b c a a I want to sort on column 1 only. The following statement does not seem to work, it still considers the rest of the line in the sorting results: sort... (2 Replies)
Discussion started by: gio001
2 Replies

5. Shell Programming and Scripting

Cut column and edit data

Mar 26 12:32:53 name sshd: 192.168.1.14 Mar 27 12:42:53 name sshd: 192.168.1.14 how to make this data in output as: "Mar 26 12:32:53","name","sshd","192.168.1.14" "Mar 27 12:42:53","name","sshd","192.168.1.14" anyone plzz help me out!!!!!!!!!!!!!! (4 Replies)
Discussion started by: jacky29
4 Replies

6. Shell Programming and Scripting

Awk or Sed, fubd match in column, then edit column.

FILE A: 9780743551526,(Abridged) 9780743551779,(Unabridged) 9780743582469,(Abridged) 9780743582483,(Unabridged) 9780743563468,(Abridged) 9780743563475,(Unabridged) FILE B: c3saCandyland 9780743518321 "CANDYLAND" "MCBAIN, ED" 2001 c3sbCandyland 9780743518321 ... (7 Replies)
Discussion started by: glev2005
7 Replies

7. Shell Programming and Scripting

sort on second column only based on first column

I have an input file like this... AAAlkalines Energizer AAAlkalines Energizer AAAlkalines Energizer AAAlkalines Sunlight AAAlkalines Sunlight AAAlkalines Sunlight AAAlkalines Energizer AAAlkalines Energizer AAAlkalines Energizer AAASalines ... (7 Replies)
Discussion started by: malcomex999
7 Replies

8. Shell Programming and Scripting

How to select and edit on a particular column?

How can I use awk to pick a particular column and work on it? For example, I want to count the number of characters in column10 that are separated by |? Thank you. (2 Replies)
Discussion started by: ivpz
2 Replies

9. Shell Programming and Scripting

Question about sort specific column and print other column at the same time !

Hi, This is my input file: ali 5 usa abc abu 4 uk bca alan 6 brazil bac pinky 10 utah sdc My desired output: pinky 10 utah sdc alan 6 brazil bac ali 5 usa abc abu 4 uk bca Based on the column two, I want to do the descending order and print out other related column at the... (3 Replies)
Discussion started by: patrick87
3 Replies

10. Shell Programming and Scripting

edit entire column from a fixed-width file using awk or sed

Col1 Col2 Col3 Col4 12 Completed 08 0830 12 In Progress 09 0829 11 For F U 07 0828 Considering the file above, how could i replace the third column the most efficient way? The actual file size is almost 1G. I am... (10 Replies)
Discussion started by: tamahomekarasu
10 Replies
Login or Register to Ask a Question