![]() |
|
|
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 |
| SED Search Pattern and Replace with the Pattern | racbern | Shell Programming and Scripting | 4 | 03-15-2008 05:59 AM |
| List files that do not match the search pattern | olapxpert | UNIX for Dummies Questions & Answers | 7 | 04-14-2005 04:49 PM |
| List files that do not match the search pattern | olapxpert | IP Networking | 1 | 04-14-2005 03:37 PM |
| pattern list? | jelizondo1010 | UNIX for Dummies Questions & Answers | 1 | 04-20-2001 09:55 AM |
| find pattern in FILES and replace it ?? | tamer | UNIX for Dummies Questions & Answers | 4 | 03-03-2001 10:30 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
using sed to replace a pattern in list of files
Hi All,
using the below grep command,I get the following output: $grep -irl "bc" /home/applmgr/amit > file_list.log $cat file_list.log /home/applmgr/amit/xyz.log /home/applmgr/amit/abc.log Requirement ========= Need sed utility to replace "bc" with "xy" pattern in the list of files i.e., file_list.log I am not getting the output while doing this way: sed -in '1,$s/bc01/xy01/g' file_list.log could anyone please help correct this..would appreciate the help.. Thanks for your time! Regards, |
|
||||
|
Your sample input and output are not coherent. Your sed expression cointains "bc01" even though none of the sample data contains "bc01". Assuming the "01" is an accident or something, the following will do what you describe, i.e. replace "bc" with "xy". Code:
sed -i 's/bc/xy/g' file_list.log The -i switch causes sed to perform the replacement in the file, i.e. replacing the file's contents with the new contents. If you have already run the failed command, it will have replaced the file with probably nothing at all, so you will need to run the grep again before you try the new script. |
|
||||
|
using sed to replace a pattern in list of files
Hi era,
Thanks for the help but it still doesn't work.. Files below consists of "bc01".. /home/applmgr/amit/xyz.log /home/applmgr/amit/abc.log If i use sed this way, it works... $ sed -i 's/bc/xy/g' xyz.log abc.log output: ===== A) cat xyz.log xy01 6000 B) cat abc.log xy01 6000 6001 My requirement is : sed -in '1,$s/bc01/xy01/g' file_list.log --should work for multiple files in file_list.log where .. $cat file_list.log /home/applmgr/amit/xyz.log /home/applmgr/amit/abc.log anyone who could suggest the correct way.. Regards, |
|
||||
|
Code:
xargs sed -i 's/bc01/xy01/g' <file_list.log The -n option causes sed to remove any line which does not match; I'm guessing you don't want that. If you do, you'll need to add a /p option to the s/// command to print the lines which had substitutions made to them; otherwise, the output will be empty files (it will make the substitution but not write the result anywhere). |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|