replace text in a file from the command line...


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers replace text in a file from the command line...
# 1  
Old 09-04-2001
Question replace text in a file from the command line...

I am having to do a lot of searching thru files to replace words. Is there a command that i can run that will alow me to hunt thru a group of files and replace one word with another without having to open each file idividually?
-thanksSmilie
# 2  
Old 09-04-2001
Sounds like you also need "sed"
http://wwwinfo.cern.ch/dis/texi2html...2/sed_toc.html

You can place this in a loop in a shell script.
You can get the files to edit from ls or find.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to pass each line of a text file as an argument to a command?

I'm looking to write a script that takes a .txt filename as an argument, reads the file line by line, and passes each line to a command. For example, it runs command --option "LINE 1", then command --option "LINE 2", etc. I am fetching object files from a library file, I have all the object file... (2 Replies)
Discussion started by: Paul Martins
2 Replies

2. Shell Programming and Scripting

sed command to replace a line in a file using line number from the output of a pipe.

Sed command to replace a line in a file using line number from the output of a pipe. Is it possible to replace a whole line piped from someother command into a file at paritcular line... here is some basic execution flow.. the line number is 412 lineNo=412 Now i have a line... (1 Reply)
Discussion started by: vivek d r
1 Replies

3. Shell Programming and Scripting

sed command to replace a line at a specific line number with some other line

my requirement is, consider a file output cat output blah sdjfhjkd jsdfhjksdh sdfs 23423 sdfsdf sdf"sdfsdf"sdfsdf"""""dsf hellow there this doesnt look good et cetc etc etcetera i want to replace a line of line number 4 ("this doesnt look good") with some other line ... (3 Replies)
Discussion started by: vivek d r
3 Replies

4. Shell Programming and Scripting

Run a command on each line of a text file

Say I have a text file, with several lines. Each line may contain spaces or the # symbol. For each line, I want to pass that line as the path of a file, in order to add it to a tar file. I've tried this but doesn't work: cat contents.txt | xargs -0 `tar -uvf contents.tar $1`Any ideas? ... (3 Replies)
Discussion started by: Tribe
3 Replies

5. UNIX for Advanced & Expert Users

Find and replace the line in text file

I have two files a.txt b.txt I want to find a line in a.txt and replace by another line from b.txt a.txt asfsdfsfsfdfsf asfwererfgdgf wrerwetretfdg b.txt werdfgdfgf werergfdgd sfdfgfgfgfgg i want to replace the 1st line of a.txt by 1st line of b.txt i want out put as (5 Replies)
Discussion started by: rammm
5 Replies

6. Shell Programming and Scripting

Replace last line of file in memory via embedded command?

Further to my earlier question regarding embedded commands I now want to delete then replace the last line in a file in memory.... FILEHERE=$((echo "$FILEHERE" | sed -e '$d' ) echo "this now added") this is throwing a syntax error but as I'm still getting used to this structure I... (1 Reply)
Discussion started by: Bashingaway
1 Replies

7. UNIX for Dummies Questions & Answers

How to search and replace a particular line in file with sed command

Hello, I have a file and in that, I want to search for a aprticular word and then replace another word in the same line with something else. Example: In file abc.txt, there is a line <host oa_var="s_hostname">test</host> I want to search with s_hostname text and then replace test with... (2 Replies)
Discussion started by: sshah1001
2 Replies

8. Shell Programming and Scripting

grep command to replace multiline text from httpd.conf file on Fedora

Hi, I am a newbie to shell scripting and to Linux environment as well. In my project I am trying to search for following text from the httpd.conf file <Directory '/somedir/someinnerdir'> AllowOverride All </Directory> and then remove this text and again rewrite the same text. The... (1 Reply)
Discussion started by: bhushan
1 Replies

9. UNIX for Dummies Questions & Answers

how can search a String in one text file and replace the whole line in another file

i am very new to UNIX plz help me in this scenario i have two text files as below file1.txt name=Rajakumar. Discipline=Electronics and communication. Designation=software Engineer. file2.txt name=Kannan. Discipline=Mechanical. Designation=CADD Design Engineer. ... (6 Replies)
Discussion started by: kkraja
6 Replies

10. UNIX for Dummies Questions & Answers

Replace line of text in a file

I need to change the first line a file from "HDR,{any_number}",,,,, where {any_number} is incremental for each file to HDR,{any_number} Can someone please suggest an easy way please Regards Col (3 Replies)
Discussion started by: colinchase
3 Replies
Login or Register to Ask a Question