![]() |
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 |
| parse of lines with different delimiters | nathasha | Shell Programming and Scripting | 9 | 05-16-2008 08:22 PM |
| extract text b/w two delimiters | dowsed4u8 | UNIX for Advanced & Expert Users | 6 | 01-18-2008 05:48 PM |
| To extract everything between two delimiters | dowsed4u8 | SUN Solaris | 1 | 01-16-2008 02:49 PM |
| Cut based on Two Delimiters at one go | pbsrinivas | Shell Programming and Scripting | 4 | 01-18-2007 04:45 AM |
| awk - treat multiple delimiters as one | peter.herlihy | Shell Programming and Scripting | 6 | 08-30-2002 12:12 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Delimiters missing
Hi
I have a pipe-delimited file where I eventually need to replace a string stored on the 3th field on a specific record. This is how the file looks like: Code:
A|Mike|Lvl 1|... B|... A|Maria|Lvl 1|... C|... B|... A|Jimmy|Lvl 2|... C|... A|Carry|Lvl 0|... C|... B|... A|John|Lvl 8|... C|... Code:
A|Mike|Lvl 3|... B|... A|Maria|Lvl 3|... C|... B|... A|Jimmy|Lvl 3|... C|... A|Carry|Lvl 0|... C|... B|... A|John|Lvl 8|... C|... Code:
awk 'BEGIN {FS="|"}{if ($1 == "A") {if ($3 == "Lvl 0" || $3 == "Lvl 1") $3="Lvl 3"};print $0}' input_file > output_file
|
|
||||
|
you need to change the output field seperator which is space by default to ' | '
Code:
awk 'BEGIN {OFS="|"; FS="|"}{if ($1 == "A") {if ($3 == "Lvl 0" || $3 == "Lvl 1") $3="Lvl 3"};print $0}' file
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|