Print only next pattern in a line after a pattern match


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Print only next pattern in a line after a pattern match
# 1  
Old 06-12-2013
Print only next pattern in a line after a pattern match

I have
Code:
2013-06-11 23:55:14 [17780] 1Umexd-0004cm-IG <= user@domain.com

I need sed/awk operation on this, so that it should print the very next pattern only after the the pattern mach <=

ie only print user@domain.com
# 2  
Old 06-12-2013
Code:
awk 'BEGIN{FS="<= ";}{print $2}'

This User Gave Thanks to rajamadhavan For This Post:
# 3  
Old 06-12-2013
Different way to enter field separator
Code:
awk -F"<= " '{print $2}'
awk '{print $2}' FS="<= "

another way
awk '{split($0,a,"<= ");print a[2]}'
This User Gave Thanks to Jotne For This Post:
# 4  
Old 06-12-2013
Thanks,

Its printing patterns after user@domain.com. I just need the next coloumn to <=

Code:
]# echo "2013-06-11 23:55:14 [17780] 1Umexd-0004cm-IG <= user@domain.com  XXX YY ZZZ" |awk 'BEGIN{FS="<= ";}{print $2}'
user@domain.com  XXX YY ZZZ

# 5  
Old 06-12-2013
Code:
echo "2013-06-11 23:55:14 [17780] 1Umexd-0004cm-IG <= user@domain.com  XXX YY ZZZ" | awk -F"<= " '{split($2,a," ");print a[1]}'
user@domain.com

This User Gave Thanks to Jotne For This Post:
# 6  
Old 06-12-2013
Code:
 echo '2013-06-11 23:55:14 [17780] 1Umexd-0004cm-IG <= user@domain.com' | perl -nle 'print $2 if /(.*)\<\=\s*(\S+)\s*/;'

# 7  
Old 06-12-2013
Thanks Jotne. Its working fine Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Match Pattern and print pattern and multiple lines into one line

Hello Experts , require help . See below output: File inputs ------------------------------------------ Server Host = mike id rl images allocated last updated density vimages expiration last read <------- STATUS ------->... (4 Replies)
Discussion started by: tigerhills
4 Replies

2. Shell Programming and Scripting

Match pattern and print the line number of occurence using awk

Hi, I have a simple problem but i guess stupid enough to figure it out. i have thousands rows of data. and i need to find match patterns of two columns and print the number of rows. for example: inputfile abd abp 123 abc abc 325 ndc ndc 451 mjk lkj... (3 Replies)
Discussion started by: redse171
3 Replies

3. Shell Programming and Scripting

Multiple pattern match and print the output in a single line

I need to match two patterns in a log file and need to get the next line of the one of the pattern (out of two patterns) that is matched, finally need to print these three values in a single line. Sample Log: 2013/06/11 14:29:04 <0999> (725102) Processing batch 02_1231324 2013/06/11... (4 Replies)
Discussion started by: rpm120
4 Replies

4. UNIX for Dummies Questions & Answers

Match Pattern after certain pattern and Print words next to Pattern

Hi experts , im new to Unix,AWK ,and im just not able to get this right. I need to match for some patterns if it matches I need to print the next few words to it.. I have only three such conditions to match… But I need to print only those words that comes after satisfying the first condition..... (2 Replies)
Discussion started by: 100bees
2 Replies

5. Shell Programming and Scripting

awk print pattern match line and following lines

Data: Pattern Data Data Data Data Data Data Data Data Data ... With awk, how do I print the pattern matching line, then the subsequent lines following the pattern matching line. Varying number of lines following the pattern matching line. (9 Replies)
Discussion started by: dmesserly
9 Replies

6. Shell Programming and Scripting

Need one liner to search pattern and print everything expect 6 lines from where pattern match made

i need to search for a pattern from a big file and print everything expect the next 6 lines from where the pattern match was made. (8 Replies)
Discussion started by: chidori
8 Replies

7. UNIX for Dummies Questions & Answers

MATCH A PATTERN AND PRINT A LINE ABOVE AND BELOW

Dear All, Hv a very specific requirement. I have a very large text file and in which I have to match a pattern and insert a line above and below. Eg: My file cat test date1 date2 date3 date4 I need to match 'date3' and insert "Reminder1" above date3 and insert 'reminder2'... (4 Replies)
Discussion started by: gokulj
4 Replies

8. Shell Programming and Scripting

Search word in a line and print earlier pattern match

Hi All, I have almost 1000+ files and I want to search specific pattern. Looking forwarded your input. Search for: word1.word2 (Which procedure contain this word, I need procedure name in output. Expected output: procedure test1 procedure test2 procedure test3 procedure test4 ... (7 Replies)
Discussion started by: susau_79
7 Replies

9. Shell Programming and Scripting

match a pattern and print the line once

Hi, I have a xml file <cisco:name> <cisco:mdNm>Cisco Device 7500 A Series</cisco:mdNm> <cisco:meNm>10.1.100.19</cisco:meNm> <cisco:ehNm>/shelf=1</cisco:ehNm> <cisco:subname> <cisco:meNm>10.1.100.19</cisco:meNm> <cisco:sptp>Cisco PortA Series</cisco:sptp> ... (11 Replies)
Discussion started by: bhagirathi
11 Replies

10. Shell Programming and Scripting

match a pattern, print it and the next line

I have a file nbu_faq.txt (Question/answer) which looks like this What I am trying to do is write out each question in a file1.txt and than the question/answer in a file2.txt like this file1.txt Q: What is nbu? Q: What is blablabla...? Q: Why ....? file2.txt Q: What is nbu? A:... (4 Replies)
Discussion started by: nymus7
4 Replies
Login or Register to Ask a Question