![]() |
|
|
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 |
| Search and replace | sanyerra | Shell Programming and Scripting | 8 | 09-16-2008 02:55 AM |
| search and replace | coolkid | Shell Programming and Scripting | 3 | 08-12-2008 06:15 PM |
| Perl: Search for string on line then search and replace text | Crypto | Shell Programming and Scripting | 4 | 01-04-2008 10:24 AM |
| Search/Replace with Sed | mvalonso | UNIX for Dummies Questions & Answers | 5 | 05-08-2006 08:30 PM |
| search and Replace | mukeshannamalai | UNIX for Advanced & Expert Users | 4 | 09-14-2001 07:21 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Search and replace using awk
Dear All,
I want to search and replace the text in file using awk. but facing hard luck in that. Please help me out!!!! > grep Abc.De.ync.rate /tmp/sdosanjh.txt Abc.De.ync.rate 6 write Now, I want to replace the "6" with value say "2". I tried the follwoing using awk.... but its not working % chgline=`cat /tmp/sdosanjh.txt | grep Abc.De.ync.rate | awk '{print ($2)}'` % echo $chgline 6 % awk 'BEGIN{OFS=FS="Abc.De.ync.rate"}$2==$chgline{$2=5} {print}' /tmp/sdosanjh.txt |
|
||||
|
Gr8 franklin it worked.
But its not preserving the file structure. Its trimming the tab spaces here as well in my reply... imagine there are two tab spaces after each field if before edit the file was Abc.De.ync.rate 6 write Now it is like below Abc.De.ync.rate 2 write Any idea how it can be preserved??? |
|
||||
|
Quote:
Code:
awk '/Abc.De.ync.rate/{$2=val}{print $1 "\t\t" val "\t\t" $3;next}{print}' val=2 /tmp/sdosanjh.txt
Regards |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|