Cat 114 files using grep or awk to pull muliple fields


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cat 114 files using grep or awk to pull muliple fields
# 1  
Old 12-15-2009
Cat 114 files using grep or awk to pull muliple fields

Files xxxxxxx.txt
Code:
------------------------------------------------------------------------------------------------------------------------------------
Req.By: xxxxxxx                           WABUSH MINES - 
xxxxxx MINE (1001)                             Page:                1
Run on: 12/14/09  at: 16:30:03                                                                              * Report:        MSB222A
                                                 PURCHASE ORDER PRINTING SUMMARY                              Version:    5.2.36.AA9
------------------------------------------------------------------------------------------------------------------------------------
 
Report Parameters:  Request Userid: xxxxx
                    Requested on:   12/14/09  at: 01:30:59
 
                    Selection Criteria:
                       Default Medium:  P Printer
                       Indicator:       Live       Y   Confirmation        Y
                       Medium:          Printed    Y   Telex               Y   Fax             Y   EDI      Y
                       Order Type:      Normal     Y   Consignment Stock   Y   Transfer Stock  Y   Workshop Y   Field Releas N
 
   PRINT RUN NUMBER: 1376
 
   CONTROL TOTALS
   No. Orders Printed for the first time           25
   No. Modified Orders Printed (all items)          0
   No. Modified Items Printed (incl. Header)        4
   Print Global Orders Indicator
   No. Orders not Printed (min order value)         0

Files xxxxxxx.txt
Code:
------------------------------------------------------------------------------------------------------------------------------------
Req.By: xxxxxxx                           Michigan MINES - 
xxxxxx MINE (1412)                             Page:                1
Run on: 12/14/09  at: 16:30:03                                                                              * Report:        MSB222A
                                                 PURCHASE ORDER PRINTING SUMMARY                              Version:    5.2.36.AA9
------------------------------------------------------------------------------------------------------------------------------------
 
Report Parameters:  Request Userid: xxxxx
                    Requested on:   12/15/09  at: 01:30:59
 
                    Selection Criteria:
                       Default Medium:  P Printer
                       Indicator:       Live       Y   Confirmation        Y
                       Medium:          Printed    Y   Telex               Y   Fax             Y   EDI      Y
                       Order Type:      Normal     Y   Consignment Stock   Y   Transfer Stock  Y   Workshop Y   Field Releas N
 
   PRINT RUN NUMBER: 1785
 
   CONTROL TOTALS
   No. Orders Printed for the first time           15
   No. Modified Orders Printed (all items)          10
   No. Modified Items Printed (incl. Header)        4
   Print Global Orders Indicator
   No. Orders not Printed (min order value)         1

There are 114 files that I have moved into thier own dir. I know how to grep and cat for a single value but what I realy need to do is pull back the following information on one or more lines from each file into one single file. The actual values will differ from file to file.
I need the following from each
Code:
xxxxxx MINE (1412) where xxxxx and 1412 will differ from file to file
PRINT RUN NUMBER: 1785 where 1785 will differ from file to file
 
 
   No. Orders Printed for the first time           15
 
   No. Modified Orders Printed (all items)          10
 
   No. Modified Items Printed (incl. Header)        4
 
   Print Global Orders Indicator                     0
 
   No. Orders not Printed (min order value)         1

Where the above numbers will differ from file to file.

I know how to grep or find for single items
Code:
find . -exec grep -l WorkOrderExtract '{}' \; >> Work.txt or
grep -il TOTAL-PICKED * > /home/mspencer/TOTAL-PICKE.txt

I just figure there has to be a way to do this better


Sorry I forgot to post the outfile.
Code:
Outfile ( all on one line)
xxxxxx MINE (1412) RUN NUMBER: 1785 Orders Printed for the first time 15 Modified Orders Printed (all items) 10 Modified Items Printed (incl. Header) 4 Global Orders Indicator 0 Orders not Printed (min order value) 1

or muliple lines using xxxxxx MINE (1412) as the break

Code:
xxxxxx MINE (1412)

RUN NUMBER: 1785 

Orders Printed for the first time 15 Modified Orders Printed (all items) 10 Modified Items Printed (incl. Header) 4 Global Orders Indicator 0 Orders not Printed (min order value) 1


Last edited by sctxms; 12-15-2009 at 10:38 AM.. Reason: code tags, please...
# 2  
Old 12-15-2009
Have you tried something like the following?
find . -exec egrep "(value1|value2)" '{}' \; >> Work.txt
# 3  
Old 12-15-2009
No the problem I have is the values will change from file to file so I do not know what to do or how to assign a search for value 1 and 2
# 4  
Old 12-15-2009
Perhaps this would work?:
Code:
awk '/Page:/             { if (s!="") print s; s=$1" "$2" "$3}
     $1 ~ /PRINT/        { s=s" "$2" "$3" "$4 }
     $1 ~ /^No\.|^Print/ { if ( $NF !~ /[0-9]+/ ) $(NF+1)=0; $1=$1; s=s" "$0 }
     END                 { if (s!="") print s } ' infile*

Output:
Code:
xxxxxx MINE (1001) RUN NUMBER: 1376 No. Orders Printed for the first time 25 No. Modified Orders Printed (all items) 0 No. Modified Items Printed (incl. Header) 4 Print Global Orders Indicator 0 No. Orders not Printed (min order value) 0
xxxxxx MINE (1412) RUN NUMBER: 1785 No. Orders Printed for the first time 15 No. Modified Orders Printed (all items) 10 No. Modified Items Printed (incl. Header) 4 Print Global Orders Indicator 0 No. Orders not Printed (min order value) 1

# 5  
Old 12-16-2009
Thanks I will try it and update the post later today or tomorrow
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk match two fields in two files

Hi, I have two TEST files t.xyz and a.xyz which have three columns each. a.xyz have more rows than t.xyz. I will like to output rows at which $1 and $2 of t.xyz match $1 and $2 of a.xyz. Total number of output rows should be equal to that of t.xyz. It works fine, but when I apply it to large... (6 Replies)
Discussion started by: geomarine
6 Replies

2. UNIX for Beginners Questions & Answers

Grep or awk a unique and specific word across many fields

Hi there, I have data with similar structure as this: CHR START-SNP END-SNP REF ALT PATIENT1 PATIENT2 PATIENT3 PATIENT4 chr1 69511 69511 A G homo hetero homo hetero chr2 69513 69513 T C . hetero homo hetero chr3 69814 69814 G C . . homo homo chr4 69815 69815 C A hetero . . hetero is... (10 Replies)
Discussion started by: daashti
10 Replies

3. Shell Programming and Scripting

Shell script to pull certain fields

I/m a beginner so be easy. I have text files that live on an AIX server. The files come in and I've been charged with writing a shell script to email out that pulls the first date, and the last date of the file. I need to load these 2 dates into 2 separate variables. I can figure out the variables,... (13 Replies)
Discussion started by: mattadams1983
13 Replies

4. Shell Programming and Scripting

Spacing off when files combined using awk or cat

I have 133 .txt files in a directory that I am combining into 1 file. The problem is when I use awk or cat to combine the files I get out put like this: output 85 138662360 KCNT1 86 138662962 KCNT1 82 138657053 KCNT1 83 138657635 KCNT1 95 138646881 KCNT1... (12 Replies)
Discussion started by: cmccabe
12 Replies

5. Shell Programming and Scripting

How do I use grep to pull incremental data and send to multiple files?

Hi Everyone, Im currently using the below code to pull data from a large CSV file and put it into smaller files with just the data associated with the number that I "grep". grep 'M053' test.csv > test053.csv Is there a way that I can use grep to run through my file like the example below... (6 Replies)
Discussion started by: TheStruggle
6 Replies

6. Shell Programming and Scripting

Sum fields of different files using awk

I'm trying to sum each field of the second column over many different files. For example: file1: file2: 1 5 1 5 2 6 2 4 3 5 3 3 To get: file3 1 10 2 10 3 8 I found answer when there are only 2 files as... (10 Replies)
Discussion started by: rogeriog.em
10 Replies

7. Shell Programming and Scripting

awk/sed inserting muliple informations in one column

I'm probably sure I need to use either awk or sed judging by research but I'm not sure what exact command I have to do to do following...:wall: So this is my text file CPU 1 2 3 4 5 6 RAM 2 3 4 5 6 7 HAR 3 4 5 6 7 8 -------------- my input: Cur_CPU=10 Cur_RAM=11 Cur_HAR=13 Desired... (5 Replies)
Discussion started by: simonirang
5 Replies

8. Shell Programming and Scripting

awk to grep rows by multiple fields

Hello, I met a challenge to extract part of the table. I'd like to grep the first three matches based on field1 and field2. Input: D A 92.85 1315 83 11 D A 95.90 757 28 3 D A 94.38 480 20 7 D A 91.21 307 21 6 D A 94.26 244 ... (6 Replies)
Discussion started by: yifangt
6 Replies

9. Programming

comparing two fields from two different files in AWK

Hi, I have two files formatted as following: File 1: (user_num_ID , realID) (the NR here is 41671) 1 cust_034_60 2 cust_80_91 3 cust_406_4 .. .. File 2: (realID , clusterNumber) (total NR here is 1000) cust_034_60 2 cust_406_4 3 .. .. (11 Replies)
Discussion started by: amarn
11 Replies

10. Shell Programming and Scripting

How to pull info under headers in file(awk,grep,while loop)

below is an extract from my file and I am trying to use Awk and grep and a while loop to pull infomation from under neath "HBA WWN=".HBA WWN=" reoccurs all over the file but the 100000c.....number are unique and I want to be able to pull and reference specifi information under this header ever time... (2 Replies)
Discussion started by: kieranfoley
2 Replies
Login or Register to Ask a Question