Computing.Net > Forums > Unix > Read file and replace..shell script

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Read file and replace..shell script

Reply to Message Icon

Name: nishad
Date: May 25, 2003 at 11:20:56 Pacific
OS: Unix
CPU/Ram: AIX
Comment:

hi,
i have an entry:
FileName=/home/mqm/adr10098/sample.dat
in a file. I want to open this file, search for "FileName=" and then replace the value with someother value(eg: /home/mqm/adr10098/another.dat) using unix shell script.

please help me with this.

thanks.




Sponsored Link
Ads by Google

Response Number 1
Name: WilliamRobertson
Date: May 26, 2003 at 11:36:12 Pacific
Reply:

You can remote-control ed (or ex or vi) using e.g:

ed test.dat < edit.macro

where edit.macro contains

g/^FileName/s/=..*/=some_other_file.dat
wq

I generally use the most basic editor that supports the edit I want to make. For vi you need to start commands with a colon.


0

Response Number 2
Name: twisgabak
Date: May 26, 2003 at 17:53:19 Pacific
Reply:

try:

cat input_file | sed `s@FileName=*@/home/mqm/adr10098/another.dat@g' > output_file

See sed command man page for more details...

Twisgabak


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


shell script Merging 2 lines



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Read file and replace..shell script

reading files in shell scripts www.computing.net/answers/unix/reading-files-in-shell-scripts/4380.html

Script: Read file to set variables www.computing.net/answers/unix/script-read-file-to-set-variables/3849.html

How would I change an entry to a file with a shell script? www.computing.net/answers/unix/how-would-i-change-an-entry-to-a-file-with-a-shell-script/1869.html