The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-07-2008
a1_win a1_win is offline
Registered User
  
 

Join Date: Apr 2005
Posts: 33
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,
  #2 (permalink)  
Old 08-07-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
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.
  #3 (permalink)  
Old 08-07-2008
a1_win a1_win is offline
Registered User
  
 

Join Date: Apr 2005
Posts: 33
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,
  #4 (permalink)  
Old 08-07-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652

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).
  #5 (permalink)  
Old 08-07-2008
a1_win a1_win is offline
Registered User
  
 

Join Date: Apr 2005
Posts: 33
thanks era now it works..

take care,

regards,
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:19 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0