######################################
# some data
# .....
######################################
file value
# param1
# param2
I want to remove the comment of the parameters but not the header...i want the file in the below format
Code:
######################################
# some data
# .....
######################################
file value
param1
param2
I have used
Code:
sed -e 's/^#[ ]*//g' <file name>
but this uncommenting the header also and giving me
Code:
######################################
some data
.....
######################################
file value
param1
param2
is there any way to start replace only after the line after "file value" ie ,if i get the file value line number (in this case 5), can we ask the sed to start replacing only after 5 th line till the end of the file
is there any way to start replace only after the line after "file value" ie ,if i get the file value line number (in this case 5), can we ask the sed to start replacing only after 5 th line till the end of the file
Code:
sed '6,$s/<pattern>/<replace_string>/g' inputfile
This User Gave Thanks to balajesuri For This Post:
One way using perl assuming the file has several headers:
Code:
$ cat infile
######################################
# some data
# .....
######################################
file value
# param1
# param2
######################################
# some data
# .....
######################################
file value
# param1
# param2
######################################
# some data
# .....
######################################
file value
# param1
# param2
######################################
# some data
# .....
######################################
file value
# param1
# param2
$ perl -lpe 'if ( m/\A#+\z/ ) { ++$header; next } if ( $header % 2 == 0 ) { s/\A[#\s]*// }' infile
######################################
# some data
# .....
######################################
file value
param1
param2
######################################
# some data
# .....
######################################
file value
param1
param2
######################################
# some data
# .....
######################################
file value
param1
param2
######################################
# some data
# .....
######################################
file value
param1
param2
I know this is not a sed solution but in vim you can do a range based search replace. That way you can see what you have done and then undo if you don't want to keep that change..
open file in vim and do the following:
Code:
:6,$s/^#//
Then if you don't like what it did:
Code:
u
To explain...
The ":" places you in command mode in vi/vim. The "6,$" is telling vi/vim to start at line "6" and end at "$" (end of file). Then the "s/^#//" tells vi/vim that we are doing a search/replace operation. Searching for "#" at the beginning of the line (^) and then in the replace side we leave blank to remove the "#" if found.
Just like sed, "s/<search>/<replace>/" uses regex. You can use regex patterns as normal in the search side. It even supports keeping part of the found string as in sed. Use "(" and ")" in the search and "\1" in the replace.
The undo is easy... simply make sure you are not in command mode by hitting the "ESC" key and then hit "u" to undo your changes (Ctrl+r for redo).
Shell script logic
Hi
I have 2 input files like with file 1 content as (file1)
"BRGTEST-242" a.txt "BRGTEST-240" a.txt "BRGTEST-219" e.txt
File 2 contents as fle(2)
"BRGTEST-244" a.txt "BRGTEST-244" b.txt "BRGTEST-231" c.txt "BRGTEST-231" d.txt "BRGTEST-221" e.txt
I want to get... (22 Replies)
Hi,
I need to compare 2 text files with around 60000 rows and 1 column. I need to compare these and write the mismatch data to 3rd file.
File1 - file2 = file3
wc -l file1.txt
58112
wc -l file2.txt
55260
head -5 file1.txt
101214200123
101214700300
101250030067
101214100500... (10 Replies)
Hi Friends,
I'm a great fan of this forum... it has helped me tone my skills in shell scripting. I have a challenge here, which I'm sure you guys would help me in achieving...
File A has a list of job ids and I need to compare this with the File B (*.log) and File C (extend *.log) and copy... (6 Replies)