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
Renaming a bunch of files tokland Shell Programming and Scripting 2 10-03-2008 10:11 AM
replace UTF-8 characters with tr ripat Shell Programming and Scripting 2 06-26-2008 08:43 AM
How do I rename a bunch of files at once? bbbngowc UNIX for Dummies Questions & Answers 8 04-21-2008 10:23 AM
Renaming a bunch of files Prashanth.m Shell Programming and Scripting 2 09-21-2005 02:16 AM
grep'ing for text within a bunch of files...? kitykity UNIX for Dummies Questions & Answers 1 09-19-2000 09:50 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 10-23-2008
subrahmaniank subrahmaniank is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 2
Replace Characters for bunch of Files.

Hi,
I am new to unix and looking out for some help in reading a file contents and replacing the characters, the requirement is I having a folder and having nearly 300 txt files, all the file contents contains some words we need to iterate all each and every files and need to find and replace it with another character.
for example I am having a folder in a defined path

/home/abc/total_files - inside the folder I am having nearly 300 txt files
like one.txt,two.txt etc.., all the text files having word called "DW" (like one.txt is having words like "DW" and two.txt is having "DW") I need write a script while read each and every file and read the contents of the file and need to find the character "DW" and change into "DW2".

Thanks in advance
Kumar
  #2 (permalink)  
Old 10-23-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,323
Could look like

Code:
you@box:/home/abc/total_files> for file in `ls -1 *.txt`; do sed 's/DW/DW2/g' ${file} > ${file}.bak; mv ${file}.bak ${file}; done

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 06:13 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