sed issue with end of line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed issue with end of line
# 1  
Old 09-24-2009
sed issue with end of line

Example,

Trying to replace text to the end of a line.

Text file looks like this

PP= 4
PP= 412
PP= 425

I want to replace only the following line:

PP= 4

with

PP= 2

How can this be done with sed?
# 2  
Old 09-24-2009
Code:
sed 's/4$/2/' filename


Last edited by varontron; 09-24-2009 at 05:44 PM..
# 3  
Old 09-24-2009
Code:
 sed s/"PP= 4"$/"PP= 2"/

between the " " whatever you want to replace

(edit: added the $
after the varontron remarks, varontron is right without it will change all PP= 4[whatever])

Last edited by Phil_FL; 09-24-2009 at 06:08 PM..
# 4  
Old 09-24-2009
you need the '$' on the end of the pattern if you want only the line ending in '4' to be changed. Phil_FL's suggestion will change all the lines containing the pattern, not just the first.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using sed to put text end of line

how to use sed to put .txt end of line..my input file below file1 make=^bak12^". DEV=LONG^cmd/usr/bak/ade4^" ..................................... file 2 make=^and_LONG/bak12^". DEV=LONG^cmd/usr/bak/ban3^" .......................................... file 3... (6 Replies)
Discussion started by: zulabc
6 Replies

2. Shell Programming and Scripting

sed removing until end of line

All: Can somebody help me out with a sed command, which removes the the first occurance of ')' until the end of the line If I have the following input ... (5 Replies)
Discussion started by: BeefStu
5 Replies

3. UNIX for Dummies Questions & Answers

Removing end of line using SED

Hello Friends, How can I remove the last two values of this line using sed John Carey:507-699-5368:29 Albert way, Edmonton, AL 25638:9/3/90:45900 The result should look like this: John Carey:507-699-5368:29 Albert way, Edmonton, AL 25638 (3 Replies)
Discussion started by: humkhn
3 Replies

4. Shell Programming and Scripting

sed : replace space and end-of-line

Hi ! I'm rather new with sed ... learned a lot already by googling etc ... The following script should replace all spaces and ends-of-lines with "something (see below). #!/bin/bash i=0 while read line do fam="H`printf "%06d" $i`" echo $line | sed -e 's//\t'$fam'\n/g' i=$(($i+1))... (7 Replies)
Discussion started by: jossojjos
7 Replies

5. UNIX for Dummies Questions & Answers

Using sed to extract a substring at end of line

This is the line that I am using: sed 's/^*\({3}*$\)/\1 /' <test.txt >results.txt and suppose that test.txt contains the following lines: http://www.example.com/200904/AUS.txt http://www.example.com/200903/_RUS.txt http://www.example.com/200902/.FRA.txt What I expected to see in results.txt... (6 Replies)
Discussion started by: figaro
6 Replies

6. Shell Programming and Scripting

end of line issue

Hello, I am getting few text files with no EOF ( or end-of-line ) which i need to fix using a command so that i can include it in a script. Now i'm fixing this issue by opening the file in "vi" editor and adding last line. e.g., server1#wc -l temp.txt 9 temp.txt server1#cat ... (6 Replies)
Discussion started by: prvnrk
6 Replies

7. Shell Programming and Scripting

delete to end of line with SED

I have a file with a bunch of similar lines in which I want to extract a phrase delimited by the first occurance of a '>' at the beginning and the first occurance of a '<' at the end (you might have guessed these are beginning/end of HTML tags). Using Sed I have managed to delete up to and... (7 Replies)
Discussion started by: coldcanuck
7 Replies

8. Shell Programming and Scripting

Number a list at end of line using 'sed'

Hi All I have a script which has produced a list, I have used 'sed' to number my list, but i want to list at end of line with the first line starting at zero (0) and brackets round it ie My List i want Hello (0) this (1) day (2) can (3) be (4) sed '/./=' filename | sed '/./N; s/\n/) /'... (5 Replies)
Discussion started by: chassis
5 Replies

9. UNIX for Dummies Questions & Answers

using sed to append text to the end of each line

Anyone know how to use SED to append a comma to the end of each line example: field1,field2,field3,field4 If i Cat /textfile ---- How can i append the end of /textfile with a comman? (8 Replies)
Discussion started by: Redg
8 Replies

10. UNIX for Dummies Questions & Answers

sed to end of line

I know this is going to be an easy anwer, but I haven't been able to figure this out - even with the help of the previous posts. I want to go from this PROD USER anon; to this TEST; I have coded a few sed commands, and none of them are getting the job done. anon will not always be the... (2 Replies)
Discussion started by: djschmitt
2 Replies
Login or Register to Ask a Question