02-02-2009
sed: Replacing two lines of text
I just created a file in vi, looks like this:
Hello nobody
nobody
What I need is to have sed change the file so it looks like this:
Hello everybody
In other words, the sed query needs to look for both instances of "nobody" before it puts the word "everybody" on the first line. Is that possible? I tried using the following scripts, but it didn't seem to work:
sed -i 's/nobody$nobody/everybody/g' testfile
sed -i 's/nobody$^nobody/everybody/g' testfile
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
hello all
I have bunch of files containing lines of text that surrounding by <# .......#> tags
I like to delete this lines from the text files whiteout open the files , can it be done with sed ?
or other unix tool (perl mybe )? (2 Replies)
Discussion started by: umen
2 Replies
2. Shell Programming and Scripting
Hi,
I have 2 sets of text files. I need to take a field from a certain line in set 1 and put it in the same place in set b. The line appears once per file, in different places but is a set format and has the unique word "ANTENNA" in it and is always 81 characters long. Example from set a:
... (7 Replies)
Discussion started by: Jonny2Vests
7 Replies
3. Shell Programming and Scripting
Hi All,
So I found a simple sed command to replace text in a file (http://www.labnol.org/internet/design/wordpress-unix-replace-text-multiple-files/1128/):
sed -e 's/OLDtext/NEWtext/' -i file(s)
Because I'm lazy and don't want to remember this each time I want to do this, I wrote the following... (4 Replies)
Discussion started by: ScKaSx
4 Replies
4. Shell Programming and Scripting
Dear All,
Regards of the Day.
I have a text file with some functions:
Function1
{
parameter 1
parameter 2
parameter 3
}
end
Function2
{
parameter 1
parameter 2
parameter 3
} (1 Reply)
Discussion started by: ashisharora
1 Replies
5. Shell Programming and Scripting
Hi,
I have the following text which I want to search and replace using perl and sed. I would appreciate any help.
Please notice the file contains schema name with a single dot and a double dot . &&WEBDIR_SCHEMA. and &&WEBDIR_SCHEMA .. }
I would like to change it to the acutal schema... (5 Replies)
Discussion started by: jville
5 Replies
6. Shell Programming and Scripting
I have a file like
blah
blah blah blah
this is the text I need,
which might be between 1-4 lines, but
always has a blank line above and below
it, and is at the end of the text file
the code tags don't show the trailing blank line. I started by deleting the last blank line with:
... (2 Replies)
Discussion started by: unclecameron
2 Replies
7. Shell Programming and Scripting
Hi friends,
This is sed & awk type question.
I have a text file which has numbers spread all over the file. I want to sum the series of numbers whenever i find it and produce an output file with the sum. For example
###start of input text file ####
abc
def
ghi
1
2
3
4
kjld
random... (3 Replies)
Discussion started by: kaaliakahn
3 Replies
8. Shell Programming and Scripting
Hi,
Can anyone help me out for my below problem.
I need to replace all System.out.println with Logger.println in *.java using SED (spanning multiple lines)
including current & sub-directories.
I tried with below command. But it is not replacing when source text is spanned over multiple... (4 Replies)
Discussion started by: Bhanu Dhulipudi
4 Replies
9. Shell Programming and Scripting
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
10. UNIX for Beginners Questions & Answers
Re: Query on using command "SED" for replacing text in bash shell
While using the command "sed" for find and replace, I wanted to know how one could find a constant and replace it with a variable inside the quotation syntax of sed?
I wanted to replace constant 3 with variable name... (3 Replies)
Discussion started by: achandra81
3 Replies