How to grep and store in a file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to grep and store in a file
# 1  
Old 09-02-2011
How to grep and store in a file

Guys, I was wondering what command can be used to parse the "LaxOrdID" field into a separate file? These messages are in thousands and I need to perform a comparision.

Code:
[BodyLength=433|MsgType=8|UserID=YYJHU|SystemID=NYH|FirmID=|OrdStatus=2|MaturityMonthYear=201109|ISLDLiquiditySource=A|ISLDClearingFirm=00000|StrikePrice=11.0000|ExecTime=15:38:38|Exch=AAA|LaxOrdID=18684016|MaturityDate=20110917|Side=1|PutOrCall=0|RemoteMatch=200984|ExecQty=10|AccountType=M|Match=1002025|SecurityType=OPT|ClearingID=00551|Source=NRCIT2|MaturityDay=17|Text=AUTOEXEC|Symbol=F|Price=0.43|Capacity=M|Date=20110901|Time=19:38:38]


Last edited by joeyg; 09-02-2011 at 10:39 AM.. Reason: Applied CodeTags to data
# 2  
Old 09-02-2011
Clarification

Is that all on one data line? Not broken into lines as pasted?
Often better to wrap CodeTags around data.

Do all the records follow the same basic layout?

So, you would want to build a file like:
Code:
LaxOrdID=18684016
LaxOrdID=18684207
LaxOrdID=19984016

# 3  
Old 09-02-2011
Yes they all follow same layout.

Each Message has same format and is repeated one after another. They are not broken into lines.

Each message starts with "MyMessage".

The format you provided, is exactly want i want.

---------- Post updated at 08:41 AM ---------- Previous update was at 08:37 AM ----------

Another example:

Code:
MyMessage [BodyLength=433|MsgType=8|UserID=AADR|SystemID=959|FirmID=|OrdStatus=2|MaturityMonthYear=201109|ISLDLiquiditySource=A|ISLDClearingFirm=00000|StrikePrice=11.0000|ExecTime=15:38:38|Exch=NSDQ|ExchOrdID=18684016|MaturityDate=20110917|Side=1|PutOrCall=0|RemoteMatch=200984|ExecQty=10|AccountType=M|Match=1002025|SecurityType=OPT|ClearingID=00551|Source=NRCIT2|MaturityDay=17|Text=AUTOEXEC|Symbol=F|Price=0.43|Capacity=M|Date=20110901|Time=19:38:38]
MyMessage [BodyLength=433|MsgType=8|UserID=AARDF|SystemID=959|FirmID=|OrdStatus=2|MaturityMonthYear=201111|ISLDLiquiditySource=R|ISLDClearingFirm=00000|StrikePrice=15.0000|ExecTime=15:40:16|Exch=NSDQ|ExchOrdID=18848552|MaturityDate=20111119|Side=2|PutOrCall=1|RemoteMatch=200989|ExecQty=33|AccountType=M|Match=1002036|SecurityType=OPT|ClearingID=00551|Source=NRCIT2|MaturityDay=19|Text=AUTOEXEC|Symbol=F|Price=0.55|Capacity=M|Date=20110901|Time=19:40:16]
MyMessage [BodyLength=433|MsgType=8|UserID=AARFG|SystemID=959|FirmID=|OrdStatus=2|MaturityMonthYear=201109|ISLDLiquiditySource=A|ISLDClearingFirm=00000|StrikePrice=11.0000|ExecTime=15:43:45|Exch=NSDQ|ExchOrdID=18882557|MaturityDate=20110902|Side=2|PutOrCall=1|RemoteMatch=201001|ExecQty=11|AccountType=M|Match=1002060|SecurityType=OPT|ClearingID=00551|Source=NRCIT2|MaturityDay=02|Text=AUTOEXEC|Symbol=F|Price=0.08|Capacity=M|Date=20110901|Time=19:43:45]

# 4  
Old 09-02-2011
If always in same layout

Code:
cut -d"|" -f13 <inputfile.txt >outputfile.txt

replace inputfile and outputfile with your actual filenames
# 5  
Old 09-02-2011
Thanks but I have a question:

When i run this command, I specifically grep for LaxORID in the output file as the file contains some other data that i dont need, and get this result:

Code:
LaxOrdID=15378205
-> LaxOrdID=15737366<8>
-> LaxOrdID=16520504<8>

is it possible that when I grep, it should come as this:

Code:
LaxOrdID=15378205
LaxOrdID=15737366<8>
LaxOrdID=16520504<8>

Instead of "--->" ?
# 6  
Old 09-02-2011
Perhaps adding the following will help

Code:
$ cat sample6.txt
LaxOrdID=15378205
-> LaxOrdID=15737366<8>
-> LaxOrdID=16520504<8>

$ cat sample6.txt | awk '{print $NF}'
LaxOrdID=15378205
LaxOrdID=15737366<8>
LaxOrdID=16520504<8>

What it does is to print the last field, where fields are separated by space character.
This User Gave Thanks to joeyg For This Post:
# 7  
Old 09-02-2011
Total genius.

Thanks (and nice dp).
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Hit multiple URL from a text file and store result in other test file

Hi, I have a problem where i have to hit multiple URL that are stored in a text file (input.txt) and save their output in different text file (output.txt) somewhat like : cat input.txt http://192.168.21.20:8080/PPUPS/international?NUmber=917875446856... (3 Replies)
Discussion started by: mukulverma2408
3 Replies

2. Shell Programming and Scripting

How to store result of grep into a variable?

In a directory i have a file *output* whose contents are changing for every simulation. zgrep "trace file is" *output* | zgrep g o/p: trace file is Int_01.1352176388z4f56ec33.0.trace.gz I want to extract "Int_01.1352176388z4f56ec33.0.trace.gz" from the above result into a variable. i... (2 Replies)
Discussion started by: twistedpair
2 Replies

3. UNIX Desktop Questions & Answers

How to store the value of grep in a variable

Hi , I was trying to store the value of a grep command to store in a variable so i can use it somewhere else in my script but i am getting error, i am using bash shell in linux: var= `grep -n "$DATE" testfile.log | head -n 1 | sed -n 's/^\(*\).*/\1/p` echo "$var"I get the error: unexpected... (5 Replies)
Discussion started by: learninguser235
5 Replies

4. Shell Programming and Scripting

Store grep output file

Hi, I'm trying to store the output from a grep, I just want the file name. But couldn't find how to do it. Basically, I just want to grep <etc> * and I want to store the file name. There is only one file with the what I'm grepping, so storing in a variable o an array its the same. If someone... (3 Replies)
Discussion started by: radicaled
3 Replies

5. Shell Programming and Scripting

grep attribute value pair and store it a variable

Hi, I have a file contains attribute value pair like.. ..name=erick rollno=583.0 pass=recon.. From the above line, i need to grep for only "rollno" and store "rollno=583.0" in a variable. Pls suggest (6 Replies)
Discussion started by: skraja1982
6 Replies

6. UNIX for Dummies Questions & Answers

Using GREP/AWK to extract a number and store it as a variable

Hello, I have a question regarding the awk command. Here is the line I need to grep: 1 F= -.13250138E+03 E0= -.13249556E+03 d E =-.174650E-01 mag= 35.2157 Instead of displaying the number in red I would like to store it as a variable such as X. Is there a way to do this? Thanks for any... (3 Replies)
Discussion started by: modey3
3 Replies

7. Shell Programming and Scripting

To read and separate number and words in file and store to two new file using shell

hi, I am a begginer in unix and i want to know how to open a file and read it and separate the numbers & words and storing it in separate files, Using shell scripting. Please help me out for this. Regards S.Kamakshi (2 Replies)
Discussion started by: kamakshi s
2 Replies

8. Shell Programming and Scripting

how to store grep command in a Variable

I have a variable A echo $A 5060 I am exporting the value X,Y,Z and it id fetching right thing and When I run C=`${X} -l ${Y} ${Z} "trap '' INT;. ~/.profile >/dev/null 2>/dev/null; netstat -na | grep \$A`" here it is going to same directory and also running netstat -na | grep 5060 ... (4 Replies)
Discussion started by: madhusmita
4 Replies

9. Shell Programming and Scripting

Grep results to store in a shell variable

I have the results of a grep with -n store in a shell variable ie VAR=`grep -n -e 'PATTERN' file` How ever I am missing the line breaks in the variable , How do I store the resualts of grep with many lines in to a variables. I want the varable should be the sawmway as we do the grep grep... (3 Replies)
Discussion started by: jojan
3 Replies

10. Shell Programming and Scripting

grep and store

When i grep a file and store it in a file it is storing as a zero byte file any way to avoid that..... (6 Replies)
Discussion started by: arunkumar_mca
6 Replies
Login or Register to Ask a Question