complicated search within file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting complicated search within file
# 1  
Old 10-03-2008
complicated search within file

Hi,
I have following problem. I have a file with time stamps and some data describing what happened between time stamps. Something like this:

10:00
meeting with K
meeting with L
11:00
lunch
12:00
work with K
13:00

From this file I have to get a file with time stamps and lines between them only if K was mentioned. So in this example the resulted file will be:

10:00
meeting with K
meeting with L
11:00
12:00
work with K
13:00

Any help will be greatly appreciated.
# 2  
Old 10-03-2008
If you only want lines beginning with the word meeting or with the time:

Code:
awk '/:/ || /^meeting/' file > new_file

Regards
# 3  
Old 10-03-2008
Thank you!
but this solves the problem only partially. I need all lines in that time period even if only one line has the pattern.
# 4  
Old 10-03-2008
Code:
cat file.txt | perl -n -e 'print if( /\d\d:\d\d/ || /^meeting/ || /\s+K/ )';

# 5  
Old 10-04-2008
Quote:
Originally Posted by mmike
Thank you!
but this solves the problem only partially. I need all lines in that time period even if only one line has the pattern.
To select those blocks with "meeting" or "work":

Code:
awk '
/meeting/ || /work/ {f=1}
/:/ && f {print s; print; s=""; f=0; next}
/:/ {s=""}
{s=s? s "\n" $0: $0}
' file > new_file

Regards
# 6  
Old 10-06-2008
In both cases I'm getting:
awk: syntax error near line 3
My box is running SunOS 5.8 Generic_117350-43 sun4u sparc SUNW,Sun-Fire-V440
# 7  
Old 10-06-2008
Use nawk, gawk or /usr/xpg4/bin/awk on Solaris.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Retrieving the relevant search from search file in the main file

I have two files: file 1: hello.com neo.com,japan.com,example.com news.net xyz.com, telecom.net, highlands.net, software.com example2.com earth.net, abc.gov.uk file 2: neo.com example.com abc.gov.uk file 2 are the search keys to search in file 1 if any of the search... (7 Replies)
Discussion started by: csim_mohan
7 Replies

2. Shell Programming and Scripting

Please help. Complicated text file manipulation problem

Let me try my best to give you a picture of what I'm trying to do. Once again I'm sorry for the essay thats coming up. I programmed a rather large library of script functions to deal with input, displaying ANSI block graphics, playing sounds, and refining the terminal and so on. I also designed... (8 Replies)
Discussion started by: tinman47
8 Replies

3. Shell Programming and Scripting

Parsing complicated CSV file with sed

Yes, there is a great doc out there that discusses parsing csv files with sed, and this topic has been covered before but not enough to answer my question (unix.com forums). I'm trying to parse a CSV file that has optional quotes like the following: "Apple","Apples, are fun",3.60,4.4,"I... (3 Replies)
Discussion started by: analog999
3 Replies

4. Shell Programming and Scripting

Search complicated strings on file

Can someone help me? I been figuring out how I can search and extract a complicated search string from a file. The whole string is delimited by a period. And the file where I'm searching is composed of differnt string such as that. For example, I have this search string: and I have a file... (3 Replies)
Discussion started by: Orbix
3 Replies

5. Shell Programming and Scripting

Script Search replace - complicated

I have a text file for which i need a script which does some fancy search and replace. Basically i want to loop through each line, if i find an occurance of certain string format then i want to carry on search on replace another line, once i replaced this line i will contine to search for the... (7 Replies)
Discussion started by: kelseyh
7 Replies

6. Emergency UNIX and Linux Support

Complicated SED search required

Hi All, I'm trying to extract all the description fields from a MIB file which contain multiple instances of the following text: ENTERPRISE compaq VARIABLES { sysName, cpqHoTrapFlags, cpqSsBoxCntlrHwLocation, cpqSsBoxCntlrIndex, cpqSsBoxBusIndex,... (10 Replies)
Discussion started by: badoshi
10 Replies

7. Shell Programming and Scripting

Parsing a Complicated properties file

Hi All, I have a requirement to parse a file. Let me clear you all on the req. I have a job which contains multiple tasks and each task will have multiple attributes that will be in the below format. Each task will have some sequence number according to that sequence number tasks shld... (1 Reply)
Discussion started by: rajeshorpu
1 Replies

8. Shell Programming and Scripting

Complicated(?) text file comparison

I've got two files, both plain text. Each file is a datafeed of products, pipe delimited. The current file is in directory 1 and yesterday's file is in directory 2 (literally, those are the directory names). What I'm trying to do is compare the files and pull out products whose price has changed... (3 Replies)
Discussion started by: Daniel M. Clark
3 Replies

9. Shell Programming and Scripting

need help with script - output to file, but complicated

ok, so what i want to do is make a script that will do the following: take out from a command in the terminal put that output into a text file already on my computer. the only thing is that i need to put the output in the file kinda weird: i need to take it and put each character of output... (13 Replies)
Discussion started by: twoodcc
13 Replies

10. Shell Programming and Scripting

Complicated string searching in a file

Hi folks, Following a part of opmn.xml file: <process-type id="OC4J_RiGHTv_PLATOR81" module-id="OC4J"> <environment> <variable id="LD_LIBRARY_PATH" value="/home/ias/v10.1.2/lib" append="true"/> <variable id="SHLIB_PATH"... (5 Replies)
Discussion started by: nir_s
5 Replies
Login or Register to Ask a Question