![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| awk and file parsing | devtakh | Shell Programming and Scripting | 4 | 05-06-2008 11:13 AM |
| Parsing xml file using Sed | kapilkinha | UNIX for Advanced & Expert Users | 3 | 04-08-2008 09:43 AM |
| Parsing a file | aol12123 | Shell Programming and Scripting | 11 | 03-25-2008 02:06 AM |
| Parsing a csv file | chiru_h | Shell Programming and Scripting | 6 | 02-12-2008 09:33 AM |
| parsing file through awk | bbeugie | Shell Programming and Scripting | 13 | 08-22-2006 01:21 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Parsing a file (sed/awk?)
Hello people, newbie question. I'm trying to parse these type of file
1 "CAR " " C1 " " " 6 0 C1 2 "CAR " " O1A" " " 8 0 O1A 3 "CAR " " O1B" " " 8 -1 O1B 4 "CAR " " C2 " " " 6 0 C2 5 "CAR " " C3 " " " 6 0 C3 6 "CAR " "H5A1" " " 8 0 H5A1 to the new one 1 "CAR " " C1 " " " 6 0 0 1 "C1" 0 2 "CAR " " O1A" " " 8 0 0 1 "O1A" 0 3 "CAR " " O1B" " " 8 -1 0 1 "O1B" 0 4 "CAR " " C2 " " " 6 0 0 1 "C2" 0 5 "CAR " " C3 " " 1f" 6 0 0 1 "C3" 0 6 "CAR " "H5A1" " " 6 0 0 1 "H5A1" 0 Every field are constant, but I have to insert the 1f value in a certain line (here the number 5) and i know previosly what is it's (i think i will use a counter to do it). Are sed/awk the best approach to do it? How is the best way to start, extract the values with awk and then modify it with sed? is a mess that some fields could have white spaces ( " C1 ", " O1B", "H5A1"). I'm starting with this, could anybody help me with the code? Thank you in advanced. Best regards. |
|
||||
|
I have a problem with white spaces, they are important for the specified file format, and using the awk command
Code:
awk '{$NF = "0 1" "\"" $NF "\" 0"; print}' myFile
Please, what could be the way to parse this lines...? HTML Code:
1 2 -5.288000 -3.217000 4.035000 1 " " X " " 2 0.17850 0.00000 "car " " C1 " " " 6 0 C1
2 15 -5.385000 -3.069000 5.276000 1 " " X " " 70 -0.64780 0.00000 "car " " O1a" " " 8 0 O1a
3 18 -6.014000 -4.000000 3.392000 1 " " X " " 70 -0.64780 0.00000 "car " " O1b" " " 8 -1 O1b
4 3 -4.190000 -2.467000 3.295000 1 " " X " " 2 0.06130 0.00000 "car " " C2 " " " 6 0 C2
5 3 -3.620000 -3.260000 2.103000 1 " " X " " 2 0.09070 0.00000 "car " " C3 " " " 6 0 C3
6 16 -2.802000 -2.377000 1.324000 1 " " X " " 70 -0.38950 0.00000 "car " " O3 " " " 8 0 O3
HTML Code:
1 2 -5.288000 -3.217000 4.035000 1 " " X " " 2 0.17850 0.00000 "CAR " " C1 " " " 6 0 0 1 "C1" 0
2 15 -5.385000 -3.069000 5.276000 1 " " X " " 70 -0.64780 0.00000 "CAR " " O1A" " " 8 0 0 1 "O1A" 0
3 18 -6.014000 -4.000000 3.392000 1 " " X " " 70 -0.64780 0.00000 "CAR " " O1B" " " 8 -1 0 1 "O1B" 0
4 3 -4.190000 -2.467000 3.295000 1 " " X " " 2 0.06130 0.00000 "CAR " " C2 " " " 6 0 0 1 "C2" 0
5 3 -3.620000 -3.260000 2.103000 1 " " X " " 2 0.09070 0.00000 "CAR " " C3 " " 1f" 6 0 0 1 "C3" 0
6 3 -2.750000 -4.417000 2.639000 1 " " X " " 2 0.14300 0.00000 "CAR " " C4 " " " 6 0 0 1 "C4" 0
|
|
||||
|
Quote:
Code:
awk -F'[ ]' '{$NF = "0 1" "\"" $NF "\"\t0"; print}' file
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|