LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-23-2011, 01:54 PM   #1
vaibhavs17
Member
 
Registered: Mar 2009
Posts: 51

Rep: Reputation: 1
extract specific content from file


there is file contains below list of 1000 sample messages. I need to extract very specific reference.Could you please provide the command, I have tried grep it did not work.

ExceptionData>2711231382 </ExceptionData>

Could you please help out

<?xml version="1.0" encoding="UTF-8" ?><ExceptionMessage><ExceptionMessageContext><ExceptionType>MATCHING</ExceptionType><ExceptionMessageFormat>XML</ExceptionMessageFormat><ExceptionMessageDetail><![CDATA[<matchingerror><eqFiTrade><salesInformation><salesmanID><salesmanIDType></salesmanIDType><salesmanIDValue>WIB </salesmanIDValue></salesmanID></salesInformation><bookingParty><entityID>840 </entityID><accountID><accountIDType>N</accountIDType><accountIDValue>83080201 </accountIDValue></accountID></bookingParty><investAgent><investAgentIDvalue></investAgentIDvalue><accountID><accountIDType>N</accountIDType><accountIDValue></accountIDValue></accountID></investAgent><counterParty><counterPartyType>S</counterPartyType><accountID><accountIDType>S</accountIDType><accountIDValue>DB INT AG </accountIDValue></accountID></counterParty><security><identifier><identifierType>0</identifierType><identifierValue>GB0005603997</identifierValue><identifierType>S</identifierType><identifierValue>LGEN.F</identifierValue></identifier><identifier><identifierType>QUICK</identifierType><identifierValue></identifierValue></identifier><securityCcy>GBP</securityCcy><securityCcy>GBP</securityCcy></security><transaction><tradeID><tradeIDType>ESPEAR </tradeIDType><tradeIDValue>2711231382 </tradeIDValue><tradeIDVersion>1</tradeIDVersion></tradeID><tradeDate>20110810</tradeDate><valueDate>20110815</valueDate><buySell>B</buySell><securityPrice><price>0.9938</price><isAvg>N</isAvg></securityPrice><securityNetPrice><price>0</price></securityNetPrice><quantity><quantityType> </quantityType><amount>1465</amount></quantity><source><tradeID><tradeIDType>GEMSLN</tradeIDType><tradeIDValue>ESPEAR-4335318873</tradeIDValue></tradeID></source><tradeLinkage><linkageType>BASKET</linkageType><linkID>LAUG10KJW</linkID></tradeLinkage><commission></commission><tax></tax><accruedInterest></accruedInterest><priceType></priceType></transaction><settlement><payCcy>GBP</payCcy><instructions><depotAccount></depotAccount><agentBicCode></agentBicCode><agentBicName></agentBicName><externalRefNo></externalRefNo><cptyPrtcpntID></cptyPrtcpntID><reasonCodes></reasonCodes><centerReference></centerReference></instructions></settlement><valuation><payCcyNetAmount>1455.92</payCcyNetAmount></valuation><claims><eSpearParentTradeRef></eSpearParentTradeRef><underlyingSecurity></underlyingSecurity><agentSourceID></agentSourceID></claims></eqFiTrade><matching><EspearReference>2711231382 </EspearReference><Exposure>0</Exposure><clientType>Contract Match Client</clientType><contractStatus>UnMatched</contractStatus><agentStatus>UnMatched</agentStatus><proposal>Yes</proposal><key>INTRASPEARTRADE2711231382 END</key><contactNumber></contactNumber><cassitNumber>100348</cassitNumber><Domicile>DE</Domicile><contractMatchRef></contractMatchRef></matching></matchingerror>]]></ExceptionMessageDetail></ExceptionMessageContext><Exception><ExceptionID>MM003221</ExceptionID><ExceptionData>2711231382 </ExceptionData><ExceptionAction>DELETE</ExceptionAction><ExceptionPriority>HIGH</ExceptionPriority></Exception></ExceptionMessage>
 
Old 08-23-2011, 02:07 PM   #2
netnix99
Member
 
Registered: Jun 2011
Distribution: redhat, CentOS, OpenBSD
Posts: 298

Rep: Reputation: 99
vaibhavs17,

You can do a MORE on the file, then grep it...


more filename | grep "ExceptionData>2711231382 </ExceptionData>"

when you do this, it will show you what you are looking for. You have to use the quotes so the string does not process the special characters in the text you are searching for.
 
1 members found this post helpful.
Old 08-23-2011, 02:16 PM   #3
vaibhavs17
Member
 
Registered: Mar 2009
Posts: 51

Original Poster
Rep: Reputation: 1
My dear friend I am looking for 1000 of messages

Quote:
Originally Posted by netnix99 View Post
vaibhavs17,

You can do a MORE on the file, then grep it...


more filename | grep "ExceptionData>2711231382 </ExceptionData>"

when you do this, it will show you what you are looking for. You have to use the quotes so the string does not process the special characters in the text you are searching for.
 
Old 08-23-2011, 02:44 PM   #4
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
What do you mean when you say grep didn't work? Post the command you used to extract the line(s) you wanted. Then, someone may be able to help you.
 
Old 08-23-2011, 02:46 PM   #5
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,623

Rep: Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964
Quote:
Originally Posted by vaibhavs17 View Post
My dear friend I am looking for 1000 of messages
Ok...then you should read the man page on grep, and look up some examples of regular expressions.

Based on your single example above, you're trying to match a 10 digit number, that has a space after it. So:
Code:
cat <your file name> | grep -o "ExceptionData>[[:digit:]]\{10\} </ExceptionData>" > <name of your output file>
Will return JUST the exception data tags and data, one per line, into an output file.
 
1 members found this post helpful.
Old 08-23-2011, 02:54 PM   #6
netnix99
Member
 
Registered: Jun 2011
Distribution: redhat, CentOS, OpenBSD
Posts: 298

Rep: Reputation: 99
Smile

Quote:
Originally Posted by vaibhavs17 View Post
My dear friend I am looking for 1000 of messages
..... in this single file, or you are looking for this information (ExceptionData>2711231382 </ExceptionData>) in 1000's of files...

sorry for the misunderstanding...
 
Old 08-23-2011, 03:15 PM   #7
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,623

Rep: Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964
Quote:
Originally Posted by netnix99 View Post
..... in this single file, or you are looking for this information (ExceptionData>2711231382 </ExceptionData>) in 1000's of files...
sorry for the misunderstanding...
Yeah, I'm not clear on it either, but the command above will work anyway. Instead of "cat <one file name>", you can do "cat *", and it will go through ALL the files in a directory, look for that pattern, and output it to a single output file.
 
Old 08-23-2011, 04:58 PM   #8
trey85stang
Senior Member
 
Registered: Sep 2003
Posts: 1,091

Rep: Reputation: 41
Quote:
Originally Posted by TB0ne View Post
Ok...then you should read the man page on grep, and look up some examples of regular expressions.

Based on your single example above, you're trying to match a 10 digit number, that has a space after it. So:
Code:
cat <your file name> | grep -o "ExceptionData>[[:digit:]]\{10\} </ExceptionData>" > <name of your output file>
Will return JUST the exception data tags and data, one per line, into an output file.
cat is not needed, just put the file name after grep string.
 
Old 08-24-2011, 09:48 AM   #9
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,623

Rep: Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964
Quote:
Originally Posted by trey85stang View Post
cat is not needed, just put the file name after grep string.
Yes, if you want to do just one file, but the OP mentioned thousands, and may need the results into a different output file.
 
Old 08-24-2011, 02:41 PM   #10
trey85stang
Senior Member
 
Registered: Sep 2003
Posts: 1,091

Rep: Reputation: 41
Quote:
Originally Posted by TB0ne View Post
Yes, if you want to do just one file, but the OP mentioned thousands, and may need the results into a different output file.
bash takes care of that for grep just as it does for cat, just use an * for the file name.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
is there a program that can extract the content of an mkv file to be combined later baronobeefdip Linux - Software 4 12-30-2010 09:18 PM
How to copy specific content of a dynamic file to another flie abhi1 Linux - Software 3 04-02-2009 06:15 AM
Extract specific directory / file from tar ust Linux - Newbie 3 09-11-2008 01:15 AM
How to extract specific directory from a TAR file? Micro420 Linux - General 4 04-18-2007 12:04 AM
An application to extract the content of flash movies under Linux Basel Linux - Software 1 02-21-2006 12:13 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration