Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

Alternative for sed -i

Original Message
Name: gounix
Date: May 3, 2007 at 04:51:23 Pacific
Subject: Alternative for sed -i
OS: sun os
CPU/Ram: 1
Model/Manufacturer: 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


Report Offensive Message For Removal


Response Number 1
Name: nails
Date: May 3, 2007 at 06:57:51 Pacific
Subject: Alternative for sed -i
Reply: (edit)
Perl supports editing in place.

Report Offensive Follow Up For Removal

Response Number 2
Name: James Boothe
Date: May 3, 2007 at 10:25:42 Pacific
Subject: Alternative for sed -i
Reply: (edit)
ed file1 << !
/text/d
w
!


Report Offensive Follow Up For Removal

Response Number 3
Name: gounix
Date: May 7, 2007 at 02:13:47 Pacific
Subject: Alternative for sed -i
Reply: (edit)
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


Report Offensive Follow Up For Removal

Response Number 4
Name: nails
Date: May 7, 2007 at 14:12:08 Pacific
Subject: Alternative for sed -i
Reply: (edit)
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...


Report Offensive Follow Up For Removal

Response Number 5
Name: gounix
Date: May 7, 2007 at 22:11:04 Pacific
Subject: Alternative for sed -i
Reply: (edit)
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



Report Offensive Follow Up For Removal


Response Number 6
Name: gounix
Date: May 10, 2007 at 03:11:10 Pacific
Subject: Alternative for sed -i
Reply: (edit)
hey ! i got the solution & its working

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

Thanks


Report Offensive Follow Up For Removal



Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Alternative for sed -i

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software




acer 312T BIOS problem

K7 Turbo possible max fsb?

Pc anywher problem

WinFLP & OE/Outlook2003

Computer resets after a few minutes


The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC