It would be better so see the example you are working on. For me personally, this is just a bit abstract. By all means, sanitise it to remove anything sensitive, but it would be useful to know.
If you are simply looking for a vi command to replace strings in a specific range of rows in a file (i.e. your script) then if you place the cursor at the start line of the range and press CNTL-G, you will get the line number displayed, e.g. line 123. Do the same at the end and let's say that tells you it's line 456. You can then issue something like:-
This will replace between lines 123 to 456 inclusive the first occurence on each line. If you want every occurrence on each line, then it's:-
I hope that this helps, but if I've missed the point, please explain more of what you want to acheive and show us the source.
Is the script beyond a re-design where you write this as a function and pass in the parameters to test/respond with?
Robin
Liverpool/Blackburn
UK
Last edited by rbatte1; 04-13-2012 at 10:44 AM..
Reason: Include the re-design question
Hi friends,
This is sed & awk type question. It is slightly different from my previous question.
I have a text file which has numbers spread all over the file. I want to sum the series of numbers (but no more than 10 numbers in series) whenever i find it and produce an output file with the... (4 Replies)
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)
So the tag for this forum says all newbies welcome...
All I want to do is go through my file and find lines which contain a given string of characters then replace these with a blank line. I really tried to find a simple command to do this but failed.
Here's what I did come up with though:
... (2 Replies)
Hi,
I have a file with many lines,
then i have following list of lines(line number 5,12,19,5,and 28) i need to replace these lines of a file with another lines as shown below these text
contains special charecter like= (/:;){}
Line_number Text to replace with
5 abc... (1 Reply)
Hi.. I'm facing a trouble in replacing two blank lines in a file using shell script...
I used sed to search a line and insert two blank lines after the searchd line using the following sed command.
sed "/data/{G;G;}/" filename . In the file, after data tag, two lines got inserted blank lines..... (4 Replies)
hey guys,
I tried searching but most 'search and replace' questions are related to one liners.
Say I have a file to be replaced that has the following:
$ cat testing.txt
TESTING
AAA
BBB
CCC
DDD
EEE
FFF
GGG
HHH
ENDTESTING
This is the input file: (3 Replies)
I have a file that has a lot of sets of a few lines of code I need to replace
start
keyword1
stuff
keyword2
end
important stuff in between
start
keyword1
stuff
keyword3
end
I want to replace each set of code (from start, to end, with a single line, call this finalcode)
I am... (2 Replies)
Hi i am trying to replace blank lines with a number 0. I tried the following code
awk '{print NF ? $0: blankrow}' blankrow = "0" file1.prg>file2.prg
however i get the following error: fatal: cannot open file `blankrow' for reading (No such file or directory)
file example:
1
2
3
5
6... (11 Replies)
Hi all,
I am trying to replace a few lines with other lines of all files in a directory which contain those few lines.
say - there are some 10 files in a dir having the same 4 lines as 1.txt at the starting
1.txt
line 1
line 2
line 3
line 4
....................................... (1 Reply)