awk how to search strings within a file from two different lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk how to search strings within a file from two different lines
# 1  
Old 06-10-2011
awk how to search strings within a file from two different lines

Hi, i would really appreciate any help anyone can give with the following info.

Thanks in advance.

I need to run a search on a file that contains thousands of trades, each trade is added into the file in blocks of 25 lines. i know the search has to take place between a time stamp specified and ends with a greater than character ">", i then need to search for two strings of digits held within the 25 lines on different lines and then set these up as variables so i can calculate the % of VAR1 to VAR2.

I've managed to get the script to work by running a read to set the time and ">" and then use the variables as my awk search string /$TIME/,/^\>/
but i'm then piping to awk and sed mulitple times which makes it look messy to gain the variable figures. (Will try to cut/paste the script in tomorrow at work)


Example of the file (underlined the search string and variables)

Code:
2011-06-05 23:04:43 data time stamp file setting
proc(1) in(34) ty(55)
ft(67) tg(56) fg(67) fd(78)
fg(67) fg(89) df(67) Tot(100)
fg(87) fg(ty) ina(67)
pre(89) fg(43) (ui) gh(45) 
rf(89) f(rt) ina(34)
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


Last edited by pludi; 06-10-2011 at 04:38 AM..
# 2  
Old 06-10-2011
Change the awk record separator so it is one record.
# 3  
Old 06-13-2011
Sorry i have no idea what that is suppose to mean ?
# 4  
Old 06-13-2011
You can use the ">>>>>" as record separator, like this:
Code:
awk 'BEGIN{RS=">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n"; FS="\n"} {print $2}' infile

proc(1) in(34) ty(55)

This User Gave Thanks to rdcwayx For This Post:
# 5  
Old 06-13-2011
A hint should be sufficient to learn to fish: awk change record separator tutorial - Google Search
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Use strings from nth field from one file to match strings in entire line in another file, awk

I cannot seem to get what should be a simple awk one-liner to work correctly and cannot figure out why. I would like to use patterns from a specific field in one file as regex to search for matching strings in the entire line ($0) of another file. I would like to output the lines of File2 which... (1 Reply)
Discussion started by: jvoot
1 Replies

2. UNIX for Dummies Questions & Answers

Search a file for certain strings and add them to the end of certain lines

I have a log file which lists groups and users in the following format GROUP1 user1 user2 user3 GROUP2 user4 user5 user6 GROUP3 user7 user8 I need to change the format to: user1|GROUP1 user2|GROUP1 user3|GROUP1 user4|GROUP2 (3 Replies)
Discussion started by: Angela S
3 Replies

3. Shell Programming and Scripting

awk search an output string between two strings

I would like to search for strings stored in searchstringfile.txt in inputfiles. searchstringfile.txt J./F. Gls. Wal F. Towerinput1.txt What is needed is J./F. 12 var Gls. Wal 16 interp. Tower 12 input2.txt Awk shall search for F. 16 pt. J./F. 22 output.txt input1.txt J./F. = 12 var... (3 Replies)
Discussion started by: sdf
3 Replies

4. Shell Programming and Scripting

awk search strings from array in textfile

I am wanting to take a list of strings and loop through a list of textfiles to find matches. Preferably with awk and parsing the search strings into an array. // Search_strings.txt tag string dummy stuff things // List of files to search in textfile1.txt textfile2.txt The... (6 Replies)
Discussion started by: sdf
6 Replies

5. Shell Programming and Scripting

Delete lines in file containing duplicate strings, keeping longer strings

The question is not as simple as the title... I have a file, it looks like this <string name="string1">RZ-LED</string> <string name="string2">2.0</string> <string name="string2">Version 2.0</string> <string name="string3">BP</string> I would like to check for duplicate entries of... (11 Replies)
Discussion started by: raidzero
11 Replies

6. Shell Programming and Scripting

Awk - find string, search lines below string for other strings

What's the easiest way to search a file for a specific string and then look for other instances after that? I want to search for all Virtual Hosts and print out the Server Name and Document Root (if it has that info), while discarding the rest of the info. Basically my file looks like this: ...... (6 Replies)
Discussion started by: Mbohmer
6 Replies

7. Shell Programming and Scripting

Using Awk to Search Two Strings on One Line

If i wanted to search for two strings that are on lines in the log, how do I do it? The following code searches for just one string that is one one line. awk '/^/ {split($2,s,",");a=$1 FS s} /failure agaf@fafa/ {b=a} END{print b}' urfile What if I wanted to search for "failure agaf@fafa"... (3 Replies)
Discussion started by: SkySmart
3 Replies

8. Shell Programming and Scripting

different take on common ?: search for two strings and remove lines between them

Thank you for assisting, I've got a partial solution just needs a tweak. Hulk-BASH$ cat somefile.txt oh there is some stuff here some more stuff here START_LABEL stuff I want more stuff I want END_LABEL other stuff here too and even more stuff here too Hulk-BASH$ Hulk-BASH$ sed... (8 Replies)
Discussion started by: laser
8 Replies

9. Shell Programming and Scripting

using AWK see the upper lines and lower lines of the strings??

Hi experts, You cool guys already given me the awk script below- awk '/9366109380/,printed==5 { ++printed; print; }' 2008-09-14.0.log Morever, i have one more things- when i awk 9366109380, i can also see the Upper 3 lines as well as below 5 lines of that string. Line 1.... (3 Replies)
Discussion started by: thepurple
3 Replies

10. Shell Programming and Scripting

awk search for Quoted strings (')

Hi All, I have files: 1. abc.sql 'This is a sample file for testing' This does not have quotations this also does not have quotations. and this 'has quotations'. here I need to list the hard coded strings 'This is a sample file for testing' and 'has quotations'. So i have... (13 Replies)
Discussion started by: kprattip
13 Replies
Login or Register to Ask a Question