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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
searching for content of files Aretai UNIX for Dummies Questions & Answers 19 03-09-2007 02:44 AM
Cleaning the content of log files jyotipg Shell Programming and Scripting 1 11-14-2006 10:19 PM
Mass Change content in all files terala Shell Programming and Scripting 1 11-19-2005 09:30 PM
Use of unzip with content files > 2Gb tcarlson Filesystems, Disks and Memory 2 09-17-2003 01:33 PM
Compare the content of 2 files odogbolu98 Shell Programming and Scripting 3 09-10-2002 08:44 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-05-2006
Registered User
 

Join Date: May 2006
Posts: 2
Stumble this Post!
content need changes- many files

Hi, all

Need some advise on this script

i have some files in a directory, and i need to change the word XX in each files to YY, how can i perform a bulk changes/

thanks in advance for yr sharing
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 10-05-2006
tayyabq8's Avatar
UNIX Hobbyist
 

Join Date: Nov 2004
Location: /World/Asia/MiddleEast/Kuwait/Salmiya
Posts: 518
Stumble this Post!
Try
Code:
#! /bin/ksh
for i in *; do
sed 's/XX/YY/g' $i > $i.tmp
mv $i.tmp $i
done
Reply With Quote
  #3 (permalink)  
Old 10-05-2006
grial's Avatar
El UNIX es como un toro
 

Join Date: Jun 2006
Location: Madrid (Spain)
Posts: 531
Stumble this Post!
That's completely true if you want to make those changes inside each file. If you want to chage just filemanes:
Code:
#! /bin/ksh
for f in *; do
new_name=$(echo $f | sed 's/XX/YY/')
mv "$f" "$new_name"
done

Regards.
Reply With Quote
  #4 (permalink)  
Old 10-05-2006
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Stumble this Post!
using perl

Code:
perl -pi -e "s/XX/YY/g" *
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:16 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0