Search a string and print the rest of line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search a string and print the rest of line
# 1  
Old 01-14-2010
Search a string and print the rest of line

Hi Guys,

I need to search a string and print the rest of the lines...

input:
Code:
8 0   90 1 0 59 20 2488 96 30006dde372 S ? 0:00 /etc/opt/SUNWconn/atm/bin/atmsnmpd -n

output:
Code:
00 /etc/opt/SUNWconn/atm/bin/atmsnmpd -n

Actually i don even need the first "00".. any suggestions is appreciated.. i am trying to split it using split . But its throwing an error.

Regards,
Magesh

---------- Post updated at 03:46 PM ---------- Previous update was at 03:44 PM ----------

Got the answer.. as soon as i posted it..

Code:
echo "8 0   90 1 0 59 20 2488 96 30006dde372 S ? 0:00 /etc/opt/SUNWconn/atm/bin/atmsnmpd -n"|awk '{ if($4 == "1"){substr("^    ","");print}}'|awk -F":" '{print $2}'



---------- Post updated at 03:59 PM ---------- Previous update was at 03:46 PM ----------

But Guys, If found one issue with it.. if we have more than one ":", then my logic gets a hit.. can anyone help me in getting the rest of the string starting from the first : .

Thanks..

Last edited by Yogesh Sawant; 01-14-2010 at 06:37 AM.. Reason: added code tags
# 2  
Old 01-14-2010
so in the 0:00:00, you need to last "00" part?
try:
Code:
awk -F"[ :]" '{print $(NF-2),$(NF-1),$NF}'

# 3  
Old 01-14-2010
try
Code:
 
$ echo  $str
8 0 90 1 0 59 20 2488 96 30006dde372 S ? 0:00 /etc/opt/SUNWconn/atm/bin/atmsnmpd -n
 
$ echo $str | sed -e 's/^.*00//g'
 /etc/opt/SUNWconn/atm/bin/atmsnmpd -n

# 4  
Old 01-14-2010
actually i am not sure.. what you are saying.. but this is wat i want

Code:
I/P

8 0   90 1 0 59 20 2488 96 30006dde372 S ? 0:00 /etc/opt/SUNWconn/atm/bin/atmsnmpd : -n adnhld : 12364

O/P:
/etc/opt/SUNWconn/atm/bin/atmsnmpd : -n adnhld : 12364

But my logic will give only
Code:
00 /etc/opt/SUNWconn/atm/bin/atmsnmpd

Your code was giving me an error

Code:
echo "8 0   90 1 0 59 20 2488 96 30006dde372 S ? 0:00 /etc/opt/SUNWconn/atm/bin/atmsnmpd -n"|awk -F"[ :]" '{print $(NF-2),$(NF-1),$NF}'
awk: trying to access field -1
 record number 1

# 5  
Old 01-14-2010
opps!! I didnt read the requirement properly.
Thought you need that part. but actually you don't.
Apologies.

try:
Code:
awk -F"[ :]" '{print $(NF-1),$NF}'



---------- Post updated at 04:20 PM ---------- Previous update was at 04:17 PM ----------

you changed the input line thats why it wont work Smilie
dont try this.

---------- Post updated at 04:22 PM ---------- Previous update was at 04:20 PM ----------

try this for the new input line:

Code:
awk -F" /" '{print $NF}'

# 6  
Old 01-14-2010
actually anchal again.. it gave me only the ones starting from the last :...

But i need all the characters starting from "first :"..
# 7  
Old 01-14-2010
I didn't understand. as per the i/p you posted, its working..
Code:
/home->echo '8 0   90 1 0 59 20 2488 96 30006dde372 S ? 0:00 /etc/opt/SUNWconn/atm/bin/atmsnmpd : -n adnhld : 12364'| awk -F" /" '{print $NF}'
etc/opt/SUNWconn/atm/bin/atmsnmpd : -n adnhld : 12364
/home->

if you need "/" also in the beginning,

Code:
/home->echo '8 0   90 1 0 59 20 2488 96 30006dde372 S ? 0:00 /etc/opt/SUNWconn/atm/bin/atmsnmpd : -n adnhld : 12364'| awk -F" /" '{print "/"$NF}'
/etc/opt/SUNWconn/atm/bin/atmsnmpd : -n adnhld : 12364
/home->

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep command to search a regular expression in a line an only print the string after the match

Hello, one step in a shell script i am writing, involves Grep command to search a regular expression in a line an only print the string after the match an example line is below /logs/GRAS/LGT/applogs/lgt-2016-08-24/2016-08-24.8.log.zip:2016-08-24 19:12:48,602 ERROR... (9 Replies)
Discussion started by: Ramneekgupta91
9 Replies

2. Shell Programming and Scripting

String search and print next all lines in one line until blank line

Dear all I want to search special string in file and then print next all line in one line until blank lines come. Help me plz for same. My input file and desire op file is as under. i/p file: A1/EXT "BSCABD1_21233G1" 757 130823 1157 RADIO X-CEIVER ADMINISTRATION BTS EXTERNAL FAULT ... (7 Replies)
Discussion started by: jaydeep_sadaria
7 Replies

3. Shell Programming and Scripting

Search several string and convert into a single line for each search string using awk command AIX?.

I need to search the file using strings "Request Type" , " Request Method" , "Response Type" and by using result set find the xml tags and convert into a single line?. below are the scenarios. Cat test Nov 10, 2012 5:17:53 AM INFO: Request Type Line 1.... (5 Replies)
Discussion started by: laknar
5 Replies

4. Shell Programming and Scripting

Search string and print the above line and below lines?.

if the first string matches then print the previous line and current line and also print the following lines if the other string search matches. Input ------ TranTime 2012 10 12 The Record starts here Accountnumber: 4632473431274 TxnCode 323 TranID 329473242834 ccsdkcnsdncskd... (7 Replies)
Discussion started by: laknar
7 Replies

5. UNIX for Dummies Questions & Answers

find string and get the rest of the line in a pipe delimited file

Hi friends, I have a file where I should search for a string and get the rest of the line but without the delimiter using awk. for example I have the series of string in a file: input_string.txt bbb ccc aaa and the mapping file looks like this. mapping.txt aaa|12 bbb|23 ccc|43... (11 Replies)
Discussion started by: kokoro
11 Replies

6. Shell Programming and Scripting

awk delete/remove rest of line on multiple search pattern

Need to remove rest of line after the equals sign on search pattern from the searchfile. Can anybody help. Couldn't find any similar example in the forum: infile: 64_1535: Delm. = 86 var, aaga 64_1535: Fran. = 57 ex. ccc 64_1639: Feb. = 26 (link). def 64_1817: mar. = 3/4. drz ... (7 Replies)
Discussion started by: sdf
7 Replies

7. Shell Programming and Scripting

Search for string and print top and bottom line

Hi Folks I need a one liner to parse through a log and if the string is found print the line above, the line with the string and the line below. example: The ball is green and blue Billy through the ball higer. Jane got hurt with the ball. So if I search for Billy I would need the 3... (1 Reply)
Discussion started by: bombcan
1 Replies

8. Shell Programming and Scripting

Print lines after the search string until blank line is found

All I want is to look for the pattern in the file...If I found it at # places... I want print lines after those pattern(line) until I find a blank line. Log EXAMPLE : MT:Exception caught The following Numbers were affected: 1234 2345 2346 Error java.lang.InternalError:... (3 Replies)
Discussion started by: prash184u
3 Replies

9. Shell Programming and Scripting

awk print second line after search string

I have multiple config files where I need to pull the ip address from loopback3. The format is the same in every file, the ip is the second line after interface loopback3. interface loopback2 loopback description router ID ip address 192.168.1.1 interface loopback3 loopback description... (3 Replies)
Discussion started by: numele
3 Replies

10. Shell Programming and Scripting

How to use sed to search for string and Print previous two lines and current line

Hello, Can anybody help me to correct my sed syntax to find the string and print previous two lines and current line and next one line. i am using string as "testing" netstat -v | sed -n -e '/test/{x;2!p;g;$!N;p;D;}' -e h i am able to get the previous line current line next line but... (1 Reply)
Discussion started by: nmadhuhb
1 Replies
Login or Register to Ask a Question