![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Problem to send rtf inline body | srik_ux | UNIX for Dummies Questions & Answers | 7 | 05-30-2008 08:30 AM |
| Array Printing Inline | vakharia Mahesh | Shell Programming and Scripting | 2 | 05-21-2008 09:53 AM |
| Inline Parameters-Urgent | indira | Shell Programming and Scripting | 2 | 05-02-2007 01:02 PM |
| variables don't work for inline "su" script | joekreif | UNIX for Advanced & Expert Users | 3 | 04-18-2007 01:30 PM |
| Will exe file size decrease while using inline function | vijaysabari | High Level Programming | 1 | 08-31-2005 07:45 AM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
I need to remove the '&' from a file.
In each line of the file, the fields are separated by ^K. I only want to remove '&' if it exists in field number 9. (example of field 9: abc&xyz) I need to do an in place/in line edit. So far I have accomplished the following: awk -F '^K' '{print $9}' $file | grep "&" | sed 's/&//g' > ./log In the above line - awk gets the field 9 - filtering using grep and only looking for field 9 with '&' - sed removes the '&' from the field and sends output to log file (input file is untouched). But, I want the input file itself to be edited. I dont need a log file. Any other options or suggestions will be helpful. Thank you |
| Forum Sponsor | ||
|
|
|
|||
|
Thank you.
{ rm file && awk '{sub(/&/,"",$9)}1' FS="\\\^K" OFS="^K" > file; } < file Questions: Does the '1' in the awk mean the first occurence of '&'? For the variable FS why do to have '\\\^K' and different for OFS "^K" ? Thanks again. |
|
||||
|
sub removes (replaces with "") the first occurrence of & in the 9th field (use gsub for global substitution or GNU Awk's gensub for more articulated substitutions).
1 is just a shortcut, it means print the current record; it can be explained like this: 1!=0 -> true -> use default action -> print $0 FS and OFS are treated differently, so in the first case we have to escape the ^ character. Last edited by radoulov; 02-21-2007 at 10:38 PM. |
| Thread Tools | |
| Display Modes | |
|
|