LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Substitute a string :) (https://www.linuxquestions.org/questions/linux-general-1/substitute-a-string-332626/)

alaios 06-11-2005 10:31 PM

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

crabboy 06-12-2005 01:31 AM

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


freegianghu 06-12-2005 04:37 AM

With recently sed, you could try:
Code:

for file in `ls *.txt`; do
  sed -i 's/String one/eno gnitS/g' $file
done


ddaas 06-12-2005 04:55 AM

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


All times are GMT -5. The time now is 12:59 PM.