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
# 8  
Old 01-14-2010
Code:
tcmsd003:/cust/home/dsdev>echo $a
8 0 90 1 0 59 20 2488 96 30006dde372 S ? 0:00 /etc/opt/SUNWconn/atm/bin/atmsnmpd : -n adnhldv :12346
tcmsd003:/cust/home/dsdev>echo $a|awk -F" /" '{print "/"$NF}'
/:12346

Mine is SunOs..
is that make any difference?
# 9  
Old 01-14-2010
I am not sure but on solaris, it is always advised to use nawk or /usr/xpg4/bin/awk .
# 10  
Old 01-14-2010
@ mac4rfree : Did you try this ?

Code:
 
$ echo "8 0   90 1 0 59 20 2488 96 30006dde372 S ? 0:00 /etc/opt/SUNWconn/atm/bin/atmsnmpd : -n adnhld : 12364" | sed 's/^.*:00 //g'
/etc/opt/SUNWconn/atm/bin/atmsnmpd : -n adnhld : 12364

# 11  
Old 01-14-2010
@xoops
yes.. but the search string should not be 00.. as you can see.. its the time.. it can change from anything 00 - 59.. that is the problem..
# 12  
Old 01-14-2010
mac4rfree your problem will be solved if you use nawk as per anchal_khare
said earlier in his code:-

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

I have test it.

Smilie
# 13  
Old 01-14-2010
yes.. that worked like charm..thanks guys.. one more doubt.. my i/p was coming from ps command and combination of awk commands.. after that i pipe the output through this.. why i am not able to assign it to a variable?

a=`command`
echo $a returns a blank..
# 14  
Old 01-14-2010
try

Code:
a=$(commands)


you need to use bash shell for above
BR

Last edited by ahmad.diab; 01-14-2010 at 07:49 AM..
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