Find column and add numbering


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find column and add numbering
# 1  
Old 06-23-2013
Find column and add numbering

Hi Masters,

Kindly need your help to format this data...
Code:
IMPORT_HORIZON_HEADER
0
0 35

SURFACE_DATA_FORMAT
XYZ-

COLOR_FORMAT
RGB


SURFACE
EB_S1_S2_Fault1 [124 0 124]
700 3
475370.187500 3672355.250000 1513.770386
475544.281250 3672530.250000 2255.540039
475662.406250 3672649.250000 2842.958008

SURFACE
EB_S1_S2_Fault1 [124 0 124]
700 3
475366.906250 3672352.000000 1514.000000
475543.156250 3672529.250000 2256.000000
475666.531250 3672653.250000 2843.000000
IMPORT_HORIZON_HEADER
0
0 35

SURFACE_DATA_FORMAT
XYZ-

COLOR_FORMAT
RGB


SURFACE
EB_S1_S2_Fault1 [124 0 124]
700 2
475240.937500 3672934.500000 1471.750000
475307.812500 3673001.750000 2772.176758

SURFACE
EB_S1_S2_Fault1 [124 0 124]
700 2
475241.437500 3672935.000000 1472.000000
475311.937500 3673005.750000 2772.000000
IMPORT_HORIZON_HEADER
0
0 35

to be
Code:
475370.187500 3672355.250000 1513.770386   1 EB_S1_S2_Fault1
475544.281250 3672530.250000 2255.540039   1 EB_S1_S2_Fault1
475662.406250 3672649.250000 2842.958008   1 EB_S1_S2_Fault1
475366.906250 3672352.000000 1514.000000   2 EB_S1_S2_Fault1
475543.156250 3672529.250000 2256.000000   2 EB_S1_S2_Fault1
475666.531250 3672653.250000 2843.000000   2 EB_S1_S2_Fault1
475240.937500 3672934.500000 1471.750000   3 EB_S1_S2_Fault1
475307.812500 3673001.750000 2772.176758   3 EB_S1_S2_Fault1
475241.437500 3672935.000000 1472.000000   4 EB_S1_S2_Fault1
475311.937500 3673005.750000 2772.000000   4 EB_S1_S2_Fault1

Please kindly need your help...
thanks and Regards,
ipatah
# 2  
Old 06-23-2013
Code:
awk '$1=="SURFACE"{++c}/\[/{v=$1}/^[0-9]/&&NF==3{$0=$0" "c" "v;print}' file

# 3  
Old 06-23-2013
Thank you Jedi,

when the fourth column reach double digit, it makes overlap with fifth column. How to make it separated

Code:
474258.531250 3674073.750000 2684.238037  9  EB_S1_S2_Fault1
473684.125000 3673496.000000 1448.000000  10  EB_S1_S2_Fault1
473860.375000 3673673.250000 1669.000000  10  EB_S1_S2_Fault1

to be

Code:
474258.531250 3674073.750000 2684.238037  9 EB_S1_S2_Fault1
473684.125000 3673496.000000 1448.000000 10 EB_S1_S2_Fault1
473860.375000 3673673.250000 1669.000000 10 EB_S1_S2_Fault1

thanks and regards,
ipatah
# 4  
Old 06-23-2013
Adjust highlighted value as per your requirement:
Code:
awk '$1=="SURFACE"{++c}/\[/{v=$1}/^[0-9]/&&NF==3{printf "%s %2d %s\n",$0,c,v}' file

# 5  
Old 06-24-2013
Thanks you very much Jedi...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Add column and multiply its result to all elements of another column

Input file is as follows: 1 | 6 2 | 7 3 | 8 4 | 9 5 | 10 Output reuired (sum of the first column $1*$2) 1 | 6 | 90 2 | 7 | 105 3 | 8 | 120 4 |9 | 135 5 |10 | 150 Please enclose sample input, sample output, and code... (5 Replies)
Discussion started by: Sagar Singh
5 Replies

2. Programming

Find the minimum value of the column with respect to other column

Hi All, I would like get the minimum value in the certain column with respect to other column. For example, I have a text file like this. ATOM 1 QSS SPH S 0 -2.790 -1.180 -2.282 2.28 2.28 ATOM 1 QSS SPH S 1 -2.915 -1.024 -2.032 2.31 2.31 ATOM 1 ... (4 Replies)
Discussion started by: bala06
4 Replies

3. Shell Programming and Scripting

awk to find maximum and minimum from column and store in other column

Need your support for below. Please help to get required output If column 5 is INV then only consider column1 and take out duplicates/identical rows/values from column1 and then put minimum value of column6 in column7 and put maximum value in column 8 and then need to do subtract values of... (7 Replies)
Discussion started by: as7951
7 Replies

4. Shell Programming and Scripting

Perl find and add to column

Hi, Could you help me with script in perl ;A1;AAA;%/A/B;70;75;-; ;A1;AAA;%/A/C;70;75;-; ;A1;BBB;%/A/G;70;75;-; ;A1;BBB;%/A;70;75;-;I would like to find line with '%/A' and put in that line in column 5 and 6 some other value ex: 90 and 99 example output: ;A1;AAA;%/A/B;70;75;-;... (5 Replies)
Discussion started by: vikus
5 Replies

5. Shell Programming and Scripting

Find String and add to next column

Dear All, I have file input input01.txt 14193 40 153 14208 40 168 14283 45 243 14298 40 258 14313 41 273 14328 44 288 ... ...input02.txt 499815.5 9886300.0 14208 94.2 1957.1 499815.5 9886300.0 14208 314.2 2101.0 ... (2 Replies)
Discussion started by: attila
2 Replies

6. Shell Programming and Scripting

Find lines with matching column 1 value, retain only the one with highest value in column 2

I have a file like: I would like to find lines lines with duplicate values in column 1, and retain only one based on two conditions: 1) keep line with highest value in column 3, 2) if column 3 values are equal, retain the line with the highest value in column 4. Desired output: I was able to... (3 Replies)
Discussion started by: pathunkathunk
3 Replies

7. Shell Programming and Scripting

to add special tag to a column based on column condition

Hi All, I have following html code <TR><TD>9</TD><TD>AR_TVR_TBS </TD><TD>85000</TD><TD>39938</TD><TD>54212</TD><TD>46</TD></TR> <TR><TD>10</TD><TD>ASCV_SMY_TBS </TD><TD>69880</TD><TD>33316</TD><TD>45698</TD><TD>47</TD></TR> <TR><TD>11</TD><TD>ARC_TBS ... (9 Replies)
Discussion started by: ckwan
9 Replies

8. Shell Programming and Scripting

sed replace values of column with ordered numbering

Hello, I am trying to write a shell script that will create a gnuplot file. My main problem is that I have a data file with two columns: 1.05929120E+09 5.0000701214792 1.05930096E+09 5.00006386985764 1.05930584E+09 5.00019465404908 1.05931072E+09 5.00031960589719 ... (2 Replies)
Discussion started by: pau
2 Replies

9. Shell Programming and Scripting

Need to add letters to a column and add in a new column subtracting from another column

So I have this input 1 10327 rs112750067 T C . PASS DP=65;AF=0.208;CB=BC,NCBI 1 10469 rs117577454 C G . PASS DP=2055;AF=0.020;CB=UM,BC,NCBI 1 10492 rs55998931 C T . PASS DP=231;AF=0.167;CB=BC,NCBI 1 10583 rs58108140 G A ... (3 Replies)
Discussion started by: kellywilliams
3 Replies

10. Shell Programming and Scripting

find expression with awk in only one column, and if it fits, print whole column

Hi. How do I find an expression with awk in only one column, and if it fits, then print that whole column. 1 apple oranges 2 bannanas pears 3 cats dogs 4 hesaid shesaid echo "which number:" read NUMBER (user inputs number 2 for this example) awk " /$NUMBER/ {field to search is field... (2 Replies)
Discussion started by: glev2005
2 Replies
Login or Register to Ask a Question