sed command to skip the first line during find and replace operation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed command to skip the first line during find and replace operation
# 1  
Old 02-14-2013
sed command to skip the first line during find and replace operation

Hi Gurus,

I did an exhaustive search for finding the script using "sed" to exclude the first line of file during find and replace.
The first line in my file is the header names.

Thanks for your help..
# 2  
Old 02-14-2013
Code:
sed '2,$s/PATTERN1/PATTERN2/' filename

Code:
awk 'NR==1{print}NR>1{sub(/PATTERN1/,"PATTERN2");print}' filename

This User Gave Thanks to Yoda For This Post:
# 3  
Old 02-15-2013
Code:
sed '1d; s/PATTERN/REPLACEMENT/' filename

This User Gave Thanks to MadeInGermany For This Post:
# 4  
Old 02-15-2013
Try
Code:
sed '1 ! s/pattern/replacement/' file

This User Gave Thanks to RudiC For This Post:
# 5  
Old 02-17-2013
Thanks..

Hello All,

Thanks for your prompt reply. All codes works well.

Sidda
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed command to replace a line in a file using line number from the output of a pipe.

Sed command to replace a line in a file using line number from the output of a pipe. Is it possible to replace a whole line piped from someother command into a file at paritcular line... here is some basic execution flow.. the line number is 412 lineNo=412 Now i have a line... (1 Reply)
Discussion started by: vivek d r
1 Replies

2. Shell Programming and Scripting

Find and replace in starting of line using sed

Hi, My requirement is, to find the word "data" and replace the starting of each line with # using sed. /dev/datavg/xxx /xxx ext3 defaults 1 2 /dev/datavg/yyy /yyy ext3 defaults 1 2 result to be #/dev/datavg/xxx /xxx ... (1 Reply)
Discussion started by: ksgnathan
1 Replies

3. Shell Programming and Scripting

sed Command to skip

Friends, I have 1000 line like below #formate Test.server.e01=http://111.22.33.23/ #test_server_west Test.server.w01=http://112.123.123.22/ Test.server.w02=http://113.143.123.22/ Test.server.w03=http://112.183.123.22/ #test_server_east Test.server.e01=http://115.123.123.22/... (6 Replies)
Discussion started by: jothi basu
6 Replies

4. Shell Programming and Scripting

sed command to replace a line at a specific line number with some other line

my requirement is, consider a file output cat output blah sdjfhjkd jsdfhjksdh sdfs 23423 sdfsdf sdf"sdfsdf"sdfsdf"""""dsf hellow there this doesnt look good et cetc etc etcetera i want to replace a line of line number 4 ("this doesnt look good") with some other line ... (3 Replies)
Discussion started by: vivek d r
3 Replies

5. Shell Programming and Scripting

Find and replace using sed command

The content of the file filea.txt is as follows. --------- case $HOSTNAME in aaa) DS_PARM_VALUE_SET=vsDev APT_Configuration_File=/appl/infoserver/Server/Configurations/2node.apt ;; bbb) DS_PARM_VALUE_SET=vsQA... (3 Replies)
Discussion started by: kmanivan82
3 Replies

6. Shell Programming and Scripting

sed find and replace command not working

Hi, Am trying to replace a character '-' with 'O' in position 289 in my file but am not success with below command. sed 's/^\(.\{289\}\)-/\1O/' filename sed: 0602-404 Function s/^\(.\{289\}\)-/\1O/ cannot be parsed. Thanks in Advance Sara Video tutorial on how to use code tags in The... (9 Replies)
Discussion started by: Sara183
9 Replies

7. Shell Programming and Scripting

sed command to find and replace

Hello All, I need a sed command to find and replace below text in multiple files in a directory. Original Text :- "$SCRIPT_PATH/files" Replace with :- "$RESOURCE_FILE" Thank you in advance !!! Regards, Anand Shah (1 Reply)
Discussion started by: anand.shah
1 Replies

8. Shell Programming and Scripting

Sed emptying file when i use for search replace operation

Hi Friends I am new to sed programming , i found that the below code can search for the $ToSearch and Replace it with $ToReplace ( $ToSearch and $ToReplace are my variables in my script ) sed "s/$ToSearch/$ToReplace/" $file > $output mv $output $file In testing the script i found that... (3 Replies)
Discussion started by: rakeshkumar
3 Replies

9. Shell Programming and Scripting

Replace all but skip first instance in a line

I have a record like the one given below. 010000306551~IN ~N~ |WINDWARD PK|Alpharetta| If ~ is present more than instance in a line,then I need to delete those instances. Any ideas? I am working in Solaris (7 Replies)
Discussion started by: prasperl
7 Replies

10. Shell Programming and Scripting

Loop with sed command to replace line with sed command in it

Okay, title is kind of confusion, but basically, I have a lot of scripts on a server that I need to replace a ps command, however, the new ps command I'm trying to replace the current one with pipes to sed at one point. So now I am attempting to create another script that replaces that line. ... (1 Reply)
Discussion started by: cbo0485
1 Replies
Login or Register to Ask a Question