LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-11-2005, 10:31 PM   #1
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203

Rep: Reputation: 45
Substitute a string :)


Good morning gentlemen /... i have some text files and i want to open them and substitute a specific string with one another.... What should i do?
Thx a lot
 
Old 06-12-2005, 01:31 AM   #2
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
This will find and replace all instances of 'LQ' with 'Linux Questions' in all .txt files in the current directory.

Code:
for i in `ls *.txt`; do
  cat $i | sed 's/LQ/Linux Questions/g' > $i.new
  chmod 777 $i
  mv $i.new $i
done
 
Old 06-12-2005, 04:37 AM   #3
freegianghu
Member
 
Registered: Oct 2004
Location: somewhere in the street
Distribution: Window$
Posts: 192

Rep: Reputation: 30
With recently sed, you could try:
Code:
for file in `ls *.txt`; do
  sed -i 's/String one/eno gnitS/g' $file
done
 
Old 06-12-2005, 04:55 AM   #4
ddaas
Member
 
Registered: Oct 2004
Location: Romania
Distribution: Ubuntu server, FreeBsd
Posts: 474

Rep: Reputation: 30
Or direct in vi:


1. open the file with vi ( #vi file-name )
2. Go to "Last Line Mode" (press : )
3. %s/string_to_replace/string_to_replace_with/g
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Substitute String or line in a file dimsh Linux - Newbie 4 09-21-2005 03:26 AM
What is best substitute for MS Access... glenn69 Linux - Software 1 08-14-2004 07:23 PM
dreamweaver - substitute? curmudgeon42 Linux - Software 1 06-03-2004 09:18 PM
java test if string in string array is null. exodist Programming 3 02-21-2004 01:39 PM
Any substitute for Dreamweaver ? Arenba Linux - Software 29 10-01-2003 05:53 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:39 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration