Error in multiple files treatment with AWK


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Error in multiple files treatment with AWK
# 1  
Old 02-09-2009
Tools Error in multiple files treatment with AWK

Hello,

My code is like that:

Code:
 
awk -v f=92238 '$1~/^m2/{tok1=1;next}tok1==1&&$0~f{tok1=0;print $NF}' inp.[1-9] inp.1[0-5]

Eahc of the "inp.*" file is like that:
Code:
...
m1 xxxx xxxx
     92238 897987
     xxxx xxxx
m2 xxxx xxxx
     92238 123435
     xxxx xxxx
...

The problem is that it returns me both the value in m1 and m2 (I asked only for the values in m2).

Any idea why my script does not return the expected result?

Thanks
# 2  
Old 02-09-2009
Finally I found!! Just posting the message helped me figuring out the solution:

In the end of the first read file, it found an occurence of ^m2 (m201), and then when it closes the first file and opens the second one, it keeps looking for "92238", and it finds it in the block "m1".

To solve this problem, just need to use ^m2$ instead of ^m2 .Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk: Print Error While Redirecting output in multiple Files

Hi, I have a following code in which I am unable to redirect to multiple files. Can anybody please help with some corrections awk -F, '{ if ( substr($1,26,2)=="02" && substr($1,184,14)=="MTSCC_VALFIRST") { array1++ array2++ array3++ } else if (substr($1,26,2)=="03" &&... (4 Replies)
Discussion started by: siramitsharma
4 Replies

2. Shell Programming and Scripting

awk, multiple files input and multiple files output

Hi! I'm new in awk and I need some help. I have a folder with a lot of files and I need that awk do something in each file and print a new file with the output. The input file name should be modified when I print the outpu files. Thanks in advance for help! :-) ciao (5 Replies)
Discussion started by: gabrysfe
5 Replies

3. Shell Programming and Scripting

perform 3 awk commands to multiple files in multiple directories

Hi, I have a directory /home/datasets/ which contains a bunch (720) of subdirectories called hour_1/ hour_2/ etc..etc.. in each of these there is a single text file called (hour_1.txt in hour_1/ , hour_2.txt for hour_2/ etc..etc..) and i would like to do some text processing in them. Each of... (20 Replies)
Discussion started by: amarn
20 Replies

4. UNIX for Dummies Questions & Answers

Using AWK: Extract data from multiple files and output to multiple new files

Hi, I'd like to process multiple files. For example: file1.txt file2.txt file3.txt Each file contains several lines of data. I want to extract a piece of data and output it to a new file. file1.txt ----> newfile1.txt file2.txt ----> newfile2.txt file3.txt ----> newfile3.txt Here is... (3 Replies)
Discussion started by: Liverpaul09
3 Replies

5. UNIX for Dummies Questions & Answers

best method of replacing multiple strings in multiple files - sed or awk? most simple preferred :)

Hi guys, say I have a few files in a directory (58 text files or somthing) each one contains mulitple strings that I wish to replace with other strings so in these 58 files I'm looking for say the following strings: JAM (replace with BUTTER) BREAD (replace with CRACKER) SCOOP (replace... (19 Replies)
Discussion started by: rich@ardz
19 Replies

6. Shell Programming and Scripting

extract multiple cloumns from multiple files; skip rows and include filenames; awk

Hello, I am trying to write a bash shell script that does the following: 1.Finds all *.txt files within my directory of interest 2. reads each of the files (25 files) one by one (tab-delimited format and have the same data format) 3. skips the first 10 rows of the file 4. extracts and... (4 Replies)
Discussion started by: manishabh
4 Replies

7. Shell Programming and Scripting

Multiple search string in multiple files using awk

Hi, filenames: contains name of list of files to search in. placelist contains the names of places to be searched in all files in "filenames" for i in $(<filenames) do egrep -f placelist $i if ] then echo $i fi done >> outputfile Output i am getting: (0 Replies)
Discussion started by: pinnacle
0 Replies

8. Shell Programming and Scripting

Splitting input files into multiple files through AWK command

Hi, I needs to split *.txt files from single directory depends on the some mutltiple input values. i have wrote the code like below for file in *.txt do grep -i -h "value1|value2" $file > $file; done. My requirment is more input values needs to be given in grep; let us say 50... (3 Replies)
Discussion started by: arund_01
3 Replies

9. Shell Programming and Scripting

Unix log treatment

Hello, I need your help for a Unix log treatment. I have a file log of this type: MEGALOG2.LOG : And I would like to have the same log in this format: In fact, for each entry log, I would just have on a single line: the date, the hour, the ID error and just the first... (2 Replies)
Discussion started by: farzolito
2 Replies
Login or Register to Ask a Question