nawk newbie


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting nawk newbie
# 8  
Old 04-05-2011
Maybe something like :
Code:
eval egrep -e '$regex' *.csv >/tmp/regex_csv.out

with a little more parsing could get the info as well.
This would only generate one *.out file, but the info would still be in
# 9  
Old 04-05-2011
Quote:
Originally Posted by bing
This is how the script looks like

Code:
regex="abx"; for file in *.csv; do nawk -v str=$regex '{if ($6 ~ str) print $1,$3,$4}' $file >$file.out; done

i need to do regular expression using '~'.

as i've many csv files, is there a way to make the above run faster other than running the script multiple times simultaneously? SmilieSmilie
If i/o (hard drive access, for example) is the bottleneck, and if all the files are on the same device, then your simultaneous instances of the script will be contending for the same limited i/o resource, which will likely result in a drop in performance.

Regardless of the bottleneck, using find with exec-+ will involve much less process creation -- which can be expensive if your files are many and a substantial portion of the work if they are also small -- thereby speeding things up (perhaps substantially).

Code:
regex=abx
find . -type f -name '*.csv' -exec awk -v re="$regex" '
    FNR == 1 { close(f); f=FILENAME".out"  }
    $6 ~ re { print $1, $3, $4 > f }
' {} +

Regards,
Alister

Last edited by alister; 04-05-2011 at 01:05 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Nawk Problem - nawk out of space in tostring on

Hi.. i am running nawk scripts on solaris system to get records of file1 not in file2 and find duplicate records in a while with the following scripts -compare nawk 'NR==FNR{a++;next;} !a {print"line"FNR $0}' file1 file2duplicate - nawk '{a++}END{for(i in a){if(a-1)print i,a}}' file1in the middle... (12 Replies)
Discussion started by: Abhiraj Singh
12 Replies

2. Shell Programming and Scripting

using nawk

help out with code. two files aaa bbb contains some records..output file xyz should be like this..see below i/p file:aaa 08350|60521|0000|505|0000|1555|000|NYCMT|Pd_1 |-11878 i/p file: bbb 60521|60510 o/p file :xyz 60510|08350|60521|0000|505|0000|1555|000|NYCMT|Pd_1 |-11878 (5 Replies)
Discussion started by: Diddy
5 Replies

3. Shell Programming and Scripting

Nesting - two nawk into one nawk

hi people; this is my two awk code: nawk '/cell+-/{r=(NF==8) ? $4FS$5FS$6 : NF==7 ? $4FS$5 : $4 ;c=split(r,rr);for (i=1;i<=c;i++){if(rr != "111111"){printf($3" %d ""\n",(i+3))}}printf("")}' /home/gc_sw/str.txt > /home/gc_sw/predwn.txt nawk -F'*' '{gsub(/ *$/,"")}$0=$1$($NF-2)'... (2 Replies)
Discussion started by: gc_sw
2 Replies

4. Shell Programming and Scripting

nawk help

Hi Gurus, I am using a script as under : read string nawk -v search="$string" ' /a/,/z/ { block = (block ? block ORS : "") $0; } /z/ { if (block ~ search) print block; } ' <File> nawk -v search="$string" ' /b/,/z/ { ... (1 Reply)
Discussion started by: vanand420
1 Replies

5. Shell Programming and Scripting

perl newbie . &&..programming newbie

Hi, I am new to programming and also to perl..But i know 'perl' can come to my rescue, But I am stuck at many places and need help..any small help is much appreciated... below is the description of what i intend to acheive with my script. I have a files named in this format... (13 Replies)
Discussion started by: xytiz
13 Replies

6. Shell Programming and Scripting

perl newbie . &&..programming newbie (question 2)

Hello everyone, I am having to do a lot of perl scripting these days and I am learning a lot. I have this problem I want to move files from a folder and all its sub folders to one parent folder, they are all .gz files.. there is folder1\folder2\*.gz and there are about 50 folders... (1 Reply)
Discussion started by: xytiz
1 Replies

7. UNIX for Dummies Questions & Answers

UNIX newbie NEWBIE question!

Hello everyone, Just started UNIX today! In our school we use solaris. I just want to know how do I setup Solaris 10 not the GUI one, the one where you have to type the commands like ECHO, ls, pwd, etc... I have windows xp and I also have vmware. I hope I am not missing anything! :p (4 Replies)
Discussion started by: Hanamachi
4 Replies

8. Shell Programming and Scripting

nawk help

What am I doing wrong here? I get syntax error. I am trying to parse a file looking for the lines with "running" as the first field then print the 5th field, then looking at the 9th field for specific values and writing the whole line to a junk file. nawk '; {if ($1 == "running")... (10 Replies)
Discussion started by: beppler
10 Replies

9. Shell Programming and Scripting

how to access values of awk/nawk variables outside the awk/nawk block?

i'm new to shell scripting and have a problem please help me in the script i have a nawk block which has a variable count nawk{ . . . count=count+1 print count } now i want to access the value of the count variable outside the awk block,like.. s=`expr count / m` (m is... (5 Replies)
Discussion started by: saniya
5 Replies

10. Shell Programming and Scripting

nawk

Hi, I had this syntax and no matter what I do, I can't get it run. err message: run6: syntax error at line 121 : `(' unexpected I went to line 121 and it's comment out! All the variables passed to nawk are valid. There are two places I suspect have the problem: 1.... (3 Replies)
Discussion started by: whatisthis
3 Replies
Login or Register to Ask a Question