Computing.Net > Forums > Unix > Alternative for sed -i

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.

Alternative for sed -i

Reply to Message Icon

Name: gounix
Date: May 3, 2007 at 04:51:23 Pacific
OS: sun os
CPU/Ram: 1
Product: 1
Comment:

Hi All,

My SUn UNIX doesn't support "-i" option for sed which edits file in place
I don't want to use intermidiate temp file to delete lines from file & write the same into original file

e.g.
I don't want
sed '/text/d' file1 > temp
mv temp file1

I am looking for alternative for
sed -i '/text/d' file1

Kindly replay if anybody has solution



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: May 3, 2007 at 06:57:51 Pacific
Reply:

Perl supports editing in place.


0

Response Number 2
Name: James Boothe
Date: May 3, 2007 at 10:25:42 Pacific
Reply:

ed file1 << !
/text/d
w
!


0

Response Number 3
Name: gounix
Date: May 7, 2007 at 02:13:47 Pacific
Reply:

Thanks nails & james.

But what i am looking for is -

I have, say 3 functions which runs in background
All functions are editing single text file to insert/update one line of record.

If i use perl , then i can not delete line from it as i am serching apttern first & deleting whole line.

Other option i tried is sed && mv
But again it is creating problem as text file gets overwirtten

If anybody can help me further?

Thanks


0

Response Number 4
Name: nails
Date: May 7, 2007 at 14:12:08 Pacific
Reply:

By this statement "3 functions runs in background" I'm assuming you have 3 different shell scripts or programs operating on the same text file.

The only way I can see that this will work is if one job finishes before the next one starts. In Unix, this functionality is implemented with a semaphore - something not normally implemented in shell scripts.

You might want to check out "Implementing Semaphores in the Shell":
http://www.samag.com/documents/s=92...

Maybe a semaphore can help you out.

There's a companion article that builds on top of the semaphore article called "Queuing jobs with qjobs":

http://www.samag.com/documents/s=98...


0

Response Number 5
Name: gounix
Date: May 7, 2007 at 22:11:04 Pacific
Reply:

Thanks nail..

But i have 3 functions in same shell script.

Okay ..i will check the given links

in meantime can you please tell me whats wrong in below line.
Bcoz it seems to solve my purpose

#!/usr/bin/bash
RUN=R1
filename=f1
perl -p -i -e 's/qq{$RUN}/\|\d\d\d\d\|[A-Z]*/R3/i' $filename

I am expecting $RUN to be expanded by shell
Also plz note my file f1 is like this
R1|1000|SUCCESS
and i am replacing it by
R3

Thanks again



0

Related Posts

See More



Response Number 6
Name: gounix
Date: May 10, 2007 at 03:11:10 Pacific
Reply:

hey ! i got the solution & its working

perl -p -i -e "S/$RUN/\|\d\d\d\d\|[A-Z]*/R3/i" $filename

Thanks


0

Sponsored Link
Ads by Google
Reply to Message Icon






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: Alternative for sed -i

Equivalent perl script for sed www.computing.net/answers/unix/equivalent-perl-script-for-sed/5939.html

alternative for awk ' substr ' www.computing.net/answers/unix/alternative-for-awk-substr-/7747.html

need help for sed www.computing.net/answers/unix/need-help-for-sed/8028.html