sed Command to skip


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed Command to skip
# 1  
Old 05-31-2013
sed Command to skip

Friends,

I have 1000 line like below

Code:
 
#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/
Test.server.e02=http://112.143.123.22/
Test.server.e03=http://116.183.123.22/

my out put of the sed command should be like below

Code:
 
#formate Test.server.e01=http://111.22.33.23/
#test_server_west
Test1.server.w01=http://112.123.123.22/
Test1.server.w02=http://113.143.123.22/
Test1.server.w03=http://112.183.123.22/
 
#test_server_east
Test1.server.e01=http://115.123.123.22/
Test1.server.e02=http://112.143.123.22/
Test1.server.e03=http://116.183.123.22/

I need to replace all the string (Test/Test1) but , i need to skip the line which is starting with (#).

Could you please help me on this.

Thanks in Advance,
JB

Last edited by jothi basu; 06-01-2013 at 06:20 AM.. Reason: the String should be (Test/Test1) not test1
# 2  
Old 05-31-2013
May be:
Code:
sed '/^#/!s/Test/&1/g' file

This User Gave Thanks to elixir_sinari For This Post:
# 3  
Old 05-31-2013
With awk
Code:
awk '!/^#/ {sub(/Test/,"Test1")}1' infile

This User Gave Thanks to Jotne For This Post:
# 4  
Old 05-31-2013
Jotne and elixir_sinari both seem to have missed that jothi basu asked not only for a "1" to be added but also for "T" to be changed to "t". And since "Test" always appears at the start of lines to be changed and only appears once, a simpler fix for the given data is:
Code:
sed 's/^Test/test1/' file

Of course, if the sample data is not representative, and "Test" actually does appear more than once in some lines or does not always appear at the start of a line, then the more complex scripts shown by others (with code to exclude comment lines) will be needed (with added changes to convert "T" to "t").
This User Gave Thanks to Don Cragun For This Post:
# 5  
Old 06-01-2013
OP is not clear on the T/t. Example output
Code:
Test1.server.w01=http://112.123.123.22/

and
Code:
Test/test1

# 6  
Old 06-01-2013
Quote:
Originally Posted by Jotne
OP is not clear on the T/t. Example output
Code:
Test1.server.w01=http://112.123.123.22/

and
Code:
Test/test1


it is typo mistake , it is like (Test/Test1) only
# 7  
Old 06-01-2013
Quote:
Originally Posted by jothi basu
it is typo mistake , it is like (Test/Test1) only
And does it only appear at the start of the a line? Or, can it appear anywhere on a line? Can it appear more than once on a line?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Output of sed command to another sed command

Hi All, I'm relatively new to Unix scripting and am trying to get my head around piping. I'm trying to take a header record from one file and prepend it to another file. I've done this by creating several temp files but i'm wondering if there is a cleaner way to do this. I'm thinking... (10 Replies)
Discussion started by: BigCroyd
10 Replies

2. Shell Programming and Scripting

sed and awk giving error ./sample.sh: line 13: sed: command not found

Hi, I am running a script sample.sh in bash environment .In the script i am using sed and awk commands which when executed individually from terminal they are getting executed normally but when i give these sed and awk commands in the script it is giving the below errors :- ./sample.sh: line... (12 Replies)
Discussion started by: satishmallidi
12 Replies

3. Red Hat

How to start Fedora 11 in command line mode and skip damaged programs ??

Hi All, Please let me know that how to start Fedora 11 in command line mode and skip damaged programs ?? Scenario being: I have Fedora 11 ( pretty ole... eh !! ). If I try to start the PC , then after some steps of startup... it just hangs and does not boots. I tried entering the mode... (4 Replies)
Discussion started by: dipanchandra
4 Replies

4. Shell Programming and Scripting

Can I skip files when running rm command

Platform: Oracle Enterprise Linux 6.2 I have several files like below. I want to remove all files except one file For example , I want to remove all the files below except dasd_91197.trc $ ls -alrt *.trc -rw-r----- 1 ecmdev wms 8438784 May 7 21:30 dasd_91177.trc -rw-r----- 1 ecmdev wms ... (3 Replies)
Discussion started by: John K
3 Replies

5. Shell Programming and Scripting

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.. (4 Replies)
Discussion started by: ks_reddy
4 Replies

6. Shell Programming and Scripting

How to skip command if it is hanging while waiting for response

Hello, I have a script that contains the command "whois 1.2.3.4" Sometimes this command takes far too long to produce any output and as a result the rest of the script is not executed. Can anyone suggest a method so that if no output is produced after say 2 seconds the script skips that... (2 Replies)
Discussion started by: colinireland
2 Replies

7. Shell Programming and Scripting

Help required on grep command(Skip the first few lines from printing in the output)

Hi experts I want the proper argument to the grep command so that I need to skip the first few lines(say first 10 lines) and print all the remaining instances of the grep output. I tried to use grep -m 10 "search text" file*. But this gives the first 10 instances(lines) of the search string.... (7 Replies)
Discussion started by: ks_reddy
7 Replies

8. 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

9. UNIX for Dummies Questions & Answers

UNIX command to skip any warning messages and continue job execution

Hello All, Good day! This is my first UNIX post. :D Anyways, I would like to seek help from you guys if you know of any UNIX command that will skip a warning message once it is encountered but continue to run the execution. Ok here's the situation in general: An encypted file is sent to... (2 Replies)
Discussion started by: jennah_rekka
2 Replies

10. Shell Programming and Scripting

find command takes a lot of time ( can I skip directories)

I have a file called "library" with the following content libnxrdbmgr.a libnxrdbmgr.so libnxtk.a libnxtk.so libora0d_nsc_osi.so I am trying to locate if these libraries are on my machine or not. find command runs for about few seconds and hangs after this. Can someone please help me and... (3 Replies)
Discussion started by: knijjar
3 Replies
Login or Register to Ask a Question