Computing.Net > Forums > Unix > sed to find and add lines

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

sed to find and add lines

Reply to Message Icon

Name: gpatel
Date: November 4, 2005 at 07:11:22 Pacific
OS: unix
CPU/Ram: 256
Comment:

Hey all,
I am trying to add a string at the end of the line. and that line should start w/ /view/
so for exaple. if you have file and the line should read
/view/hello/thankyou/file.bin
/view/yes/red/blue.bin

i wanted to add @@good.bin at end of the both line so it should read
/view/hello/thankyou/file.bin@@good.bin
/view/yes/red/blue.bin@@good.bin

so basically anything start with /view should have @@good.bin at the end of the line. can someone help me w/ a script or anything.
thanks a lot
~gpatel


thanks,
Gaurav



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: November 4, 2005 at 08:28:25 Pacific
Reply:

Implementing if statements in sed isn't a lot of fun. Here's an alternate way:

#!/bin/ksh

#!/bin/ksh

while read line
do
[[ $line = "/view"* ]] && line="$line"@@good.bin
echo "$line"
done < data.file > newmyfile



0

Response Number 2
Name: gpatel
Date: November 4, 2005 at 08:50:40 Pacific
Reply:

thanks a lot nails

thanks,
Gaurav


0

Response Number 3
Name: gpatel
Date: November 6, 2005 at 19:52:33 Pacific
Reply:

if the lines above lines start like this how can i change the program

File input =/view/hello/thankyou/file.bin@@good.bin
File Input1
=/view/yes/red/blue.bin@@good.bin

the program was writter to assume that line start w/ /view but the line start w/ File Input or anything else. how can i still use the program. like can i use something like line*/view* or something like that?
thanks,
GPATEL


0

Response Number 4
Name: nails
Date: November 11, 2005 at 09:43:07 Pacific
Reply:

Sorry I missed your later post. You want to flag any line that has /view in it? This should work:

#!/bin/ksh

while read line
do
[[ $line = *"/view"* ]] && line="$line"@@good.bin
echo "$line"
done < data.file


0
Reply to Message Icon

Related Posts

See More


awking a file Free unix falvor



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: sed to find and add lines

grep to find a specific line number www.computing.net/answers/unix/grep-to-find-a-specific-line-number/6484.html

find and replace stings www.computing.net/answers/unix/find-and-replace-stings/3865.html

parameters to sed doesnt work www.computing.net/answers/unix/parameters-to-sed-doesnt-work/7467.html