01-18-2007
how to replace one line in text with several lines
Hi,
I need to replace a specific line in a text (eg the line contains the word MYSERVER) with a number of lines (let's say 4) in which the word MYSERVER will be replaced with
server1 in the first line
server2 in the second line
server3 in the 3rd line
server4 in the 4th line
The original text would be something like
lline1
line2
line3
THIS IS THE LINE WITH MYSERVER
line4
line5
The resulting text should be like:
lline1
line2
line3
THIS IS THE LINE WITH server1
THIS IS THE LINE WITH server2
THIS IS THE LINE WITH server3
THIS IS THE LINE WITH server4
line4
line5
If anyone could help with this it would be great!
Thank you.
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
I need to change the first line a file from
"HDR,{any_number}",,,,,
where {any_number} is incremental for each file
to
HDR,{any_number}
Can someone please suggest an easy way please
Regards
Col (3 Replies)
Discussion started by: colinchase
3 Replies
2. UNIX for Advanced & Expert Users
I have a file which contains the following data.
Parameters "CParameters"
BEGIN DSSUBRECORD
Name "TgtDB"
Prompt "TgtDB"
Default "edwdev"
ParamType "0"
ParamLength "0"
ParamScale "0"
END DSSUBRECORD
MetaBag... (6 Replies)
Discussion started by: ukatru
6 Replies
3. UNIX for Dummies Questions & Answers
hi all,
i am new bee to Unix.
i know how to replace text for range of lines in vi
for e.g. replace | with |||| for line 4 through 7 using vi
: 4,7s/|/||||/g
but i have to replace | with |||| only for line no 4, 7 and 10 using vi only!!!
your help will be appreciated!
thanks,... (4 Replies)
Discussion started by: pranav.pandya
4 Replies
4. UNIX for Dummies Questions & Answers
I want to replace this line : "test compare visible] true" and make it "#test compare visible] true".
How can I do it ? And it should be checked in many sub folder files also. (6 Replies)
Discussion started by: manoj.b
6 Replies
5. Shell Programming and Scripting
i have something like this...
cat filename.txt
<complexType name="abc">
bklah vlah
blah
blha blha blah
blha
</complexType >
<complexType name="def">
bklah vlah
blah
blha blha blah
blha
</complexType >
.
.
.and so on.. its a very large file (11 Replies)
Discussion started by: vivek d r
11 Replies
6. Shell Programming and Scripting
Hi,
i want to replace
"Hi How
are You when
did you go to
delhi"
to
"Hi How
are you when
did you come from
delhi"
in a file.
Any idea how to do it? (2 Replies)
Discussion started by: abhitanshu
2 Replies
7. Shell Programming and Scripting
Literally cannot get this one, guys. Single line replacement is simple, but I am not understanding the correct syntax for including a new line feed into the substitution part.
Here's what I got. (Cannot use perl)
#!/bin/sh
set -f
#Start Perms
export HOME=/home/test_user
# End Perms... (6 Replies)
Discussion started by: Parallax
6 Replies
8. Shell Programming and Scripting
I have a file which requires modification via a shell script.
Need to do the following: 0. take input from user for new text. 1. search for a keyword in the file. 2. replace the line next to this to this keyword with user supplied input.
for e.g., my file has the following text:
(some... (7 Replies)
Discussion started by: chingupt
7 Replies
9. UNIX for Dummies Questions & Answers
I want to replace lines. The files 1 are (separated by \t)
Gm01 phytozome9_0 three_prime_UTR 70641 70759 . - . ID=PAC:26323927.three_prime_UTR.1;Parent=PAC:26323927;pacid=26323927
Gm01 phytozome9_0 three_prime_UTR 90230 90692 . - . ... (1 Reply)
Discussion started by: grace_shen
1 Replies
10. Shell Programming and Scripting
Have multiple files with the same format and certain text is the same. Have specific text to search for and then need to replace the next line. Can search on the text DEVICE and multiple lines will be found. The line after each DEVICE line has {. Want to replace the line { with {-someadditiontext.... (2 Replies)
Discussion started by: bigdaddywags
2 Replies
fmt(1) General Commands Manual fmt(1)
NAME
fmt - format text
SYNOPSIS
width] [file...]
DESCRIPTION
The command is a simple text formatter that fills and joins lines to produce output lines of (up to) the number of characters specified in
the width option. The default width is 72. concatenates the arguments. If none are given, formats text from the standard input.
Blank lines are preserved in the output, as is the spacing between words. does not fill lines beginning with a period for compatibility
with Nor does it fill lines starting with
Indentation is preserved in the output and input lines with differing indentation are not joined (unless is used).
can also be used as an in-line text filter for the command:
reformats the text between the cursor location and the end of the paragraph.
Options
recognizes the following options:
Crown margin mode.
Preserve the indentation of the first two lines within a paragraph and align the left margin of each subsequent line with that
of the second line. This is useful for tagged paragraphs.
Split lines only.
Do not join short lines to form longer ones. This prevents sample lines of code, and other such "formatted" text, from being
unduly combined.
Fill output lines to up to
width columns.
WARNINGS
The width option is acceptable for BSD compatibility, but it may go away in future releases.
SEE ALSO
nroff(1), vi(1).
fmt(1)