Extract a specific string from a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extract a specific string from a file
# 1  
Old 03-08-2013
Extract a specific string from a file

Hi,
I have a file whose contents are as follows.

Code:
 
2013-03-08/15:09:20.134 INFO 00000000-00000000 0034 09700400 CON_IN SessionID:ED5E1400-4805-85E2-17B2-5BE45684886A Connection
ID:ED5E1400-4805-68F1-BB1D-F06496BCF910 TO:<sip:51234999@10.239.94.146:5060 FROM:<sip:9302280716@97.208.31.7:51024
2013-03-08/15:09:34.779 INFO 00000000-00000000 0034 09700400 CON_IN SessionID:ED5E1400-4805-568A-AB66-C0AA90D48172 Connection
ID:ED5E1400-4805-D2F9-2BDA-9338ADC5ACBF TO:<sip:512344117697822948@10.239.94.146:5060 FROM:<sip:9301523741@97.208.31.7:51072
2013-03-08/15:09:55.119 INFO 00000000-00000000 0034 09700400 CON_IN SessionID:ED5E1400-4805-9C21-ADFF-1E6AB87E562F Connection
ID:ED5E1400-4805-A07F-28CE-5314F42FCE91 TO:<sip:51234999@10.239.94.146:5060 FROM:<sip:9302280716@97.208.31.7:51024
2013-03-08/15:09:59.045 INFO 00000000-00000000 0034 09700400 CON_IN SessionID:ED5E1400-4805-C6B3-2D2E-7994B60B4590 Connection
ID:ED5E1400-4805-1B97-1070-864D13D9C2C0 TO:<sip:5123441196190255@10.239.94.146:5060 FROM:<sip:9324450637@97.208.31.7:51024
2013-03-08/15:10:15.681 INFO 00000000-00000000 0034 09700400 CON_IN SessionID:ED5E1400-4805-6DBE-7789-ADB5AB6A228E Connection
ID:ED5E1400-4805-83A5-069B-E64686C99B37 TO:<sip:51234567@10.239.94.146:5060 FROM:<sip:8657716656@97.208.31.7:51104
2013-03-08/15:10:27.713 INFO 00000000-00000000 0034 09700400 CON_IN SessionID:ED5E1400-4805-E0B3-B445-657CD6D38E69 Connection
ID:ED5E1400-4805-6041-52BC-59EAEDF34687 TO:<sip:51234777@10.239.94.146:5060 FROM:<sip:9303890865@97.208.31.7:51072

Please help me to extract all instances of the string that starts with "FROM:".

Thanks,
Sunil

Moderator's Comments:
Mod Comment please use code tags instead of icode tags for entire lines

Last edited by Scrutinizer; 03-08-2013 at 08:13 AM.. Reason: icode -> code
# 2  
Old 03-08-2013
Try:
Code:
awk -FFROM: 'NF>1{print $2}' file

Code:
sed -n 's/.*FROM://p' file

This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 03-08-2013
Quote:
Originally Posted by Scrutinizer
Try:
Code:
awk -FFROM: 'NF>1{print $2}' file

Code:
sed -n 's/.*FROM://p' file

Thanks. The awk command worked fine.

Best Regards,
Sunil
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How-To Extract specific data from a file.

data.txt has several information like the below.. <SERVER>:WEB:MYDOM01:/tmp/cong/MYDOM01,/tmp/app/MYDOM01 <WEBER>:CANES:https-web01,https-web02:/web/apps/https-web01/config <SERVER>:WEB:MYDOM07:/tmp/cong/MYDOM07,/tmp/app/MYDOM07... (7 Replies)
Discussion started by: mohtashims
7 Replies

2. Shell Programming and Scripting

How to extract every repeated string between two specific string?

Hello guys, I have problem with hpux shell script. I have one big text file that contains like SOH bla bla bla bla bla bla ETX SOH bla bla bla ETX SOH bla bla bla ETX What I need to do is save first SOH*BLA into file1.txt, save second SOH*BLA into file2.txt and so on.... (17 Replies)
Discussion started by: sembii
17 Replies

3. Shell Programming and Scripting

Extract specific line in an html file starting and ending with specific pattern to a text file

Hi This is my first post and I'm just a beginner. So please be nice to me. I have a couple of html files where a pattern beginning with "http://www.site.com" and ending with "/resource.dat" is present on every 241st line. How do I extract this to a new text file? I have tried sed -n 241,241p... (13 Replies)
Discussion started by: dejavo
13 Replies

4. UNIX for Dummies Questions & Answers

Search for a specific String in a log file for a specific date range

Hi, I have log file which rolls out every second which is as this. HttpGenRequest - -<!--OXi dbPublish--> <created="2014-03-24 23:45:37" lastMsgId="" requestTime="0.0333"> <response request="getOutcomeDetails" code="114" message="Request found no matching data" debug="" provider="undefined"/>... (3 Replies)
Discussion started by: karthikprakash
3 Replies

5. Shell Programming and Scripting

extract specific string and rename file

Hi all, I am working on a small prog.. i have a file.txt which contains random data... K LINES V4 ADD CODE `COMPANY` ADD CODE `DISTRIBUTOR` SEQ NAME^K LINES V5 SEQ NAME^K LINES V6 ADD `PACK-LDATE` SEQ NAME^K^KCOMMAND END^KHEADINFO... (1 Reply)
Discussion started by: mukeshguliao
1 Replies

6. Shell Programming and Scripting

Extract specific lines from a file

Hi, I have a file which contains DDL statements- CREATE TABLE, CREATE INDEX, ALTER TABLE etc. I have to only pick CREATE TABLE statements from the file- Source : ---------------------------------------------- --DDL for table abc -------------------------------------------- CREATE TABLE... (4 Replies)
Discussion started by: newb
4 Replies

7. Shell Programming and Scripting

Extract specific content from a file

My input file: >sequence_1 ASSSSSSSSSSSDDDDDDDDDDDCCCCCCC ASDSFDFFDFDFFWERERERERFSDFESFSFD >sequence_2 ASDFDFDFFDDFFDFDSFDSFDFSDFSDFDSFASDSADSADASD ASDFFDFDFASFASFASFAFSFFSDASFASFASFAFS >sequence_3 VEDFGSDGSDGSDGSDGSDGSDGSDG dDFSDFSDFSDFSDFSDFSDFSDFSDF SDGFDGSFDGSGSDGSDGSDGSDGSDG My... (22 Replies)
Discussion started by: patrick87
22 Replies

8. Shell Programming and Scripting

to extract specific value in a file

Hi Friends, I have a file with the following values.. xyz.txt,12345.xml abc.txt,04567.xml cde.txt,12134.xml I would like to extract all the 2nd column values like 12345 04567 12134 Please advice!! (3 Replies)
Discussion started by: techmoris
3 Replies

9. Shell Programming and Scripting

Search for string in a file and extract another string to a variable

Hi, guys. I have one question: I need to search for a string in a file, and then extract another string from the file and assign it to a variable. For example: the contents of the file (group) is below: ... ftp:x:23: mail:x:34 ... testing:x:2001 sales:x:2002 development:x:2003 ...... (6 Replies)
Discussion started by: daikeyang
6 Replies

10. Shell Programming and Scripting

Extract specific pattern from a file

Hi All, I am a newbie to Shell Scripting. I have a File The Server Name XXX002 ------------------------- 2.1 LAPD Iface Id Link MTU Side ecc_3_1 4 Up 512 User ecc_3_2 5 Up 512 User The Server Name XXX003 ------------------------- 2.1 LAPD (4 Replies)
Discussion started by: athreyavc
4 Replies
Login or Register to Ask a Question