Computing.Net > Forums > Unix > Modifying a file in KSH

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.

Modifying a file in KSH

Reply to Message Icon

Name: abby
Date: July 10, 2002 at 11:54:08 Pacific
Comment:

Hi all,
I'm trying to modify a file using ksh script.
I need to parse the file and then look for a specific occurence of a pattern and then assign it a value.
After that I need to save the file with the same filename. Is there any way to accomplish it without creating a temporary file ? For modification, which is a better bet (sed/awk) ?
Thanks in advance.



Sponsored Link
Ads by Google

Response Number 1
Name: Frank
Date: July 11, 2002 at 07:06:05 Pacific
Reply:

Hi abby,

it is unusal for unix commands to overwrite him self.
So choose C, C++.

No RISK no fun
Frank


0

Response Number 2
Name: Faraz Rehman
Date: July 17, 2002 at 11:41:11 Pacific
Reply:


Frank,

Seems like you wanna do "Search and Replace" operation on a text file right? For example if you want to find every single occurrence of "string_1" in "my_file" and replace it with "string_2" you might try following

"perl -i.bak -p -e 's/string_1/string_2/g;' my_file"

Remove the *.bak file if you don't want to keep it

If you do not have perl on your system you can try

"sed 's/string_1/string_2/g;' my_file"

This will send changed file to std out, that you can save later

Hope this helps

- Faraz


0

Response Number 3
Name: Frank
Date: July 21, 2002 at 02:50:39 Pacific
Reply:

Faraz,

read the question from abby and give here an answer.
Seems so that you only read my answer and comment it.

I didn't see any value in your posting to the question "how to make changes in a file whitout creating a temp file".


No RISK no fun
Frank


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







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: Modifying a file in KSH

how to replace a file in a .zip fil www.computing.net/answers/unix/how-to-replace-a-file-in-a-zip-fil/7497.html

How to attach a file in a mail (UNIX script) www.computing.net/answers/unix/how-to-attach-a-file-in-a-mail-unix-script/8487.html

how to get the modified time of a file www.computing.net/answers/unix/how-to-get-the-modified-time-of-a-file/2110.html