Visit Our UNIX and Linux User Community


Complex search and output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Complex search and output
# 1  
Old 08-18-2009
Complex search and output

Hi,

I have somewhat of a complex task at hand. I am on a HP-UX box and I need to search for information embedded in files, further embedded into a file/folder structure.

I compiled a list of information that I need found:

File=list.csv

DATE FIELD 1 FIELD2
08/13/09,EMCU9629413,YMLZ4807940
08/13/09,TCKU9085252,CCLZ400809
08/14/09,EMCU9678634,FLXZ412869

Directory Structure

/edi/backup/out/done/ega/090812/multiple files
/edi/backup/out/done/ega/090813/multiple files
/edi/backup/out/done/ega/090814/multiple files
...and so on, and so on...

File Structure

CATOS2EDI....
CNTR...
CARR...
PORT...
DOC...
TRACE....

The above is one complete document. The starting segment of a document is "CATOS2EDI" and the ending segment of that same document is "TRACE". There are be multiple documents within one file.

FIELD1 & FIELD2 will always be in the same segment, the CNTR segment.

I need to:

1. Use the DATE field in the file as a string to get the file from the write directory.
i.e. Make a variable from the DATE field in the file: 08/13/09 ~> 090813
2. Search for FIELD1 & FIELD2 in that directory.
i.e. grep -e ^CNTR.*FIELD1.*FIELD2 /edi/backup/out/done/ega/$DTE
3. Return only the document that FIELD1 & FIELD2 were found.
i.e. Not sure how to return this information.
NOTE: There can be more segments in between the CATOS2EDI and TRACE segment, but there is only one start segment with one end segment to indicate on complete document.

Expected Results:

3 Documents in 1 file:

CATOS2EDI....
CNTR...EMCU9629413YMLZ4807940
CARR...
PORT...
DOC...
TRACE....
CATOS2EDI....
CNTR...TCKU9085252CCLZ400809
CARR...
PORT...
DOC...
TRACE....
CATOS2EDI....
CNTR...TCKU9085252CCLZ400809
CARR...
PORT...
DOC...
TRACE....

NOTE: The output does not look like this exactly, but I just wanted to illustrate the starting (CATOS2EDI) and ending (TRACE) segments.

Please let me know if there is an easy way to do this or if you have any questions.

Thanks,
Chris
# 2  
Old 09-02-2009
You can search on this forum for ways to reformat dates using grep, which is what you will need to get started on question 1 and 2. I am only answering to your query since your post is indeed rather complex and you are more likely to get reusable answers if you split up your issue in more digestible chunks. Or better even: post code that you are using and which does not work as expected.
# 3  
Old 09-07-2009
Thanks for the advice. Is there a way to just delete this post?

Previous Thread | Next Thread
Test Your Knowledge in Computers #144
Difficulty: Easy
IEEE designed POSIX around the common structure of the major competing variants of the Unix system, publishing the first POSIX standard in 1988.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search the specific content from the complex file

Hi, I have a file with complex data without delimiter, have requirement to fetch the specific record based on some charcters. here is my file data ... (12 Replies)
Discussion started by: Riverstone
12 Replies

2. Shell Programming and Scripting

Complex Output Filtering

Hi, I have this command on my linux jmap -heap $pid | grep '%\|:' the output of which is like below: I need a smart way to check if any of these memory usage crosses 95%, 90% and 85% i need to triggerAlert accordingly. I know how to trigger email alerts however I need a good way to... (3 Replies)
Discussion started by: mohtashims
3 Replies

3. Shell Programming and Scripting

Read in search strings from text file, search for string in second text file and output to CSV

Hi guys, I have a text file named file1.txt that is formatted like this: 001 , ID , 20000 002 , Name , Brandon 003 , Phone_Number , 616-234-1999 004 , SSNumber , 234-23-234 005 , Model , Toyota 007 , Engine ,V8 008 , GPS , OFF and I have file2.txt formatted like this: ... (2 Replies)
Discussion started by: An0mander
2 Replies

4. Shell Programming and Scripting

awk command for complex search and print

Input: 9999~cbc~100~209~ozzxczcz~10001001001~100~abc10 123~a~sdklfjl~sldoi~~~ksjdfnkjsdf~123456 125~g~sdklfjl~slsdfsdfsdfsdfdoi~~~~~~~~ksjdfnkjsdf~345 127~wera~sdklfjl~sldoi~~~ksjdfnkjsdf~123 128~awer~swerwerdklfjl~sldoi~~~ksjdfnkjsf~1da2345... (7 Replies)
Discussion started by: onesuri
7 Replies

5. Shell Programming and Scripting

Complex string search query.

Hi, I wish to find the latest occurance of the below string in my log file. Once found, I need to search the below string after the above string and display this Request 331489 has passed or Request 331489 has failed I would like my query to be platform... (11 Replies)
Discussion started by: mohtashims
11 Replies

6. Shell Programming and Scripting

word search in output

How to get the fisrt word of the output of a shell script . below command will display the list of baselines in my view . cmd : cleartool lsstream -fmt "%NXp\n" -view $VIEW_NAME Output : baseline:MHC_BUILDTREE1.0.1 baseline:JEPG_DUIF_CI baseline:MOR_BuildTree_BLD_I.0.1 I need to... (2 Replies)
Discussion started by: saku
2 Replies

7. Shell Programming and Scripting

search 3 file and write to 4th file (a bit complex)

hi buddies; rollbackip.txt:10.14.3.65 2 10.14.3.65 3 ... lookup.txt: ... 10.14.3.65 2 10.14.5.55 1 55 10.14.6.66 1 66 10.14.3.65 3 10.14.7.77 3 77 10.14.8.88 2 88 10.14.9.99 4 99 ... ip-port.txt ... port111 3 10.14.5.55 57 port111 2 10.14.5.55 51 port111 1 10.14.5.55 59 ->... (7 Replies)
Discussion started by: gc_sw
7 Replies

8. Shell Programming and Scripting

Replacing text between Tags, with output from a complex command

The Problem I have n files all named "conf.cfg", each of which contain a line that reads: "MyVar=XXX", where XXX can be any value. I have a second file called report.xml, that might read: <Reports> <Report>Report1</Report> <Report>Report2</Report> <Report>Report3</Report> </Reports> I... (1 Reply)
Discussion started by: Flang
1 Replies

9. UNIX for Advanced & Expert Users

Complex Input/Output Redirect

Hi All, Sorry if the title is not good but I did not know how to explain with only some words! What I meant is: I have a unix command built from a private application vendor that when executed it prompts for two entries by the keyboard, let's say, for example: ... (1 Reply)
Discussion started by: felipe.vinturin
1 Replies

10. Shell Programming and Scripting

Complex Search/Replace Multiple Files Script Needed

I have a rather complicated search and replace I need to do among several dozen files and over a hundred occurrences. My site is written in PHP and throughout the old code, you will find things like die("Operation Aborted due to....."); For my new design skins for the site, I need to get... (2 Replies)
Discussion started by: UCCCC
2 Replies

Featured Tech Videos