Finding and replacing whole line using sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding and replacing whole line using sed
# 1  
Old 03-20-2011
Finding and replacing whole line using sed

Hi all,

assume that i am having the following line in a file called file1.

triumph and disaster must be treated same.

I want to replace this line with.

follow excellence success will chase you.

is it possible to do this using sed. if possible kindly post me the code.
# 2  
Old 03-20-2011
Code:
sed -i 's/triumph and disaster must be treated same./follow excellence success will chase you./' file1

This User Gave Thanks to kato For This Post:
# 3  
Old 03-20-2011
Hi kato,

Thanks it works!!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk sed to repeat every character on same position from the upper line replacing whitespace

Hello is it possible with awk or sed to replace any white space with the previous line characters in the same position? I am asking this because the file I have doesn't always follow a pattern. For example the file I have is the result of a command to obtain windows ACLs: icacls C:\ /t... (5 Replies)
Discussion started by: nakaedu
5 Replies

2. Shell Programming and Scripting

Replacing lines matching a multi-line pattern (sed/perl/awk)

Dear Unix Forums, I am hoping you can help me with a pattern matching problem. What am I trying to do? I want to replace multiple lines of a text file (that match a multi-line pattern) with a single line of text. These patterns can span several lines and do not always have the same number of... (10 Replies)
Discussion started by: thefang
10 Replies

3. Shell Programming and Scripting

Replacing a line in a file using sed

I have a file which has a list in it pop triangle people slow fast What I want to do is search this list and replace people with humans do the list looks like this: pop triangle human slow fast I think i use something like this.... if cat /list.txt | grep -q 'people' ; then (9 Replies)
Discussion started by: digitalviking
9 Replies

4. Shell Programming and Scripting

SED Replacing all but one regex match on a line or specific matches

Hi, I'm attempting to rename some files that have spaces in them. Without linking sed commands together is it possible to replace the first three "." to " ". File.name.is.long.ext -> File name is long.ext I can get the desired effect with echo "File.name.is.long.ext" | sed 's/\./ /g;s/... (5 Replies)
Discussion started by: vectox
5 Replies

5. Shell Programming and Scripting

error while replacing a string by new line character in sed

hi, when i am doing the following things getting error Can anyone please suggest i have a file where there is a line like the following branch=dev sdf dev jin kilii fin kale boyle dev james dev i want to search the existance of dev in the above line. cat "$file" | sed -n... (8 Replies)
Discussion started by: millan
8 Replies

6. Shell Programming and Scripting

awk or sed for finding closest pattern to a line number

hi guys, I want to do pattern matching with awk or sed but I don't know how. here's what I want: I have a line number for a pattern that I have already found using grep, and I know a pattern like "---" that happens a few lines above that certain line number. I want to print out the chunk... (1 Reply)
Discussion started by: alirezan
1 Replies

7. UNIX for Dummies Questions & Answers

Finding nth occurrence in line and replacing it

Hi, I have several files with data that have to be imported to a database. These files contain records with separator characters. Some records are corrupt (2 separators are missing) and I need to correct them prior to importing them into the db. Example: ... (5 Replies)
Discussion started by: stresing
5 Replies

8. UNIX for Dummies Questions & Answers

Sed replacing a whole line with a new line

I am needing to replace a whole line of code in a file with a new line of code. This is what I need to do. I need to replace. $db_url = 'mysql://test_dev:test12@localhost/test'; With $db_url = 'mysql://$dbuser:$dbpass@localhost/$dbase'; OK this is where it gets complicated. The... (4 Replies)
Discussion started by: filmguy
4 Replies

9. Shell Programming and Scripting

sed.. Add new line after finding text

I know that this my be really simple, but I'm having a hard time accomplishing it. I am trying to add a new line of text after finding a particular string of text in a file. Here's what I'm getting: sed: command garbled: N/search_string/\\new_text/ I was using "N" to add a line after the... (3 Replies)
Discussion started by: douknownam
3 Replies

10. UNIX for Dummies Questions & Answers

finding a line with sed

Hi, I know you can use sed with a line number to find a line in a file and print it but can for the life of me not remember or find the syntax today! Any help greatly appreciated! Thanks (2 Replies)
Discussion started by: maverick
2 Replies
Login or Register to Ask a Question