awk changes to make it faster


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk changes to make it faster
# 1  
Old 05-16-2013
awk changes to make it faster

I have script like below, who is picking number from one file and and searching in another file, and printing output.

Bu is is very slow to be run on huge file.can we modify it with awk

Code:
#! /bin/ksh
while read line1
do
echo "$line1"
a=`echo $line1`
if [ $a -ge 0 ]
then
echo "$num"
cat file1|nawk -v "c=$line1" '$1 ~ c' >> message.log
fi
done < file2

.

file2 has below data
Code:
cat file2
1234
5678
9100
1324

file 1 has string which contain this data in that.
# 2  
Old 05-16-2013
Can you post some of file 1 and example on how you like the output to be.
# 3  
Old 05-16-2013
first four line should be printed, last two should be ignored
Code:
1234,0130020036210801,61400900240,144.135.15.1,50501,8,9550,106A,177200093,144.135.15.212,telstra.internet,mnc001.mcc505.gprs,33,10.237.103.20,0,1,0,0,0,2413,36436,20121002232313,115914,
5678,0124300042019104,61432228629,149.135.133.97,50501,8,6550,2120,80847635,144.135.14.68,telstra.internet,mnc001.mcc505.gprs,33,10.195.135.22,0,1,0,0,0,1962,19782,20121002234954,116855,
9100,0131760091070905,61427989363,149.135.131.65,50501,8,3950,4557,83767434,144.135.14.67,telstra.internet,mnc001.mcc505.gprs,33,100.82.223.99,0,1,0,0,0,235,3324,20121002233018,117271,0,
1324,3524240501157114,61427252411,149.135.133.97,50501,8,A050,0D9E,178201226,144.135.15.212,telstra.internet,mnc001.mcc505.gprs,33,10.239.140.179,0,1,0,0,0,2288,48700,20121002231512,1171
2222,0131760091070905,61427989363,149.135.131.65,50501,8,3950,4557,83767434,144.135.14.67,telstra.internet,mnc001.mcc505.gprs,33,100.82.223.99,0,1,0,0,0,235,3324,20121002233018,117271,0,
2154,3524240501157114,61427252411,149.135.133.97,50501,8,A050,0D9E,178201226,144.135.15.212,telstra.internet,mnc001.mcc505.gprs,33,10.239.140.179,0,1,0,0,0,2288,48700,20121002231512,1171

# 4  
Old 05-16-2013
Try this
Code:
awk -F, 'NR==FNR{a[$0];next} $1 in a' file2 file1

Code:
1234,0130020036210801,61400900240,144.135.15.1,50501,8,9550,106A,177200093,144.135.15.212,telstra.internet,mnc001.mcc505.gprs,33,10.237.103.20,0,1,0,0,0,2413,36436,20121002232313,115914,
5678,0124300042019104,61432228629,149.135.133.97,50501,8,6550,2120,80847635,144.135.14.68,telstra.internet,mnc001.mcc505.gprs,33,10.195.135.22,0,1,0,0,0,1962,19782,20121002234954,116855,
9100,0131760091070905,61427989363,149.135.131.65,50501,8,3950,4557,83767434,144.135.14.67,telstra.internet,mnc001.mcc505.gprs,33,100.82.223.99,0,1,0,0,0,235,3324,20121002233018,117271,0,
1324,3524240501157114,61427252411,149.135.133.97,50501,8,A050,0D9E,178201226,144.135.15.212,telstra.internet,mnc001.mcc505.gprs,33,10.239.140.179,0,1,0,0,0,2288,48700,20121002231512,1171

# 5  
Old 05-16-2013
Jotne assumes the keys are first in file1, separated by comma.
nawk wants ($1 in a).
# 6  
Old 05-16-2013
So you say that it should be?
Code:
awk -F, 'NR==FNR{a[$0];next} ($1 in a)' file2 file1

Gives same result.

I do understand it like this:
Print lines from file1 if its staring with one of the numbers listed in file2
This User Gave Thanks to Jotne For This Post:
# 7  
Old 05-16-2013
Thank you so much, its working great
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to make faster loop in multiple directories?

Hello, I am under Ubuntu 18.04 Bionic. I have one shell script run.sh (which is out of my topic) to run files under multiple directories and one file to control all processes running under those directories (control.sh). I set a cronjob task to check each of them with two minutes of intervals.... (3 Replies)
Discussion started by: baris35
3 Replies

2. Shell Programming and Scripting

How to make awk command faster for large amount of data?

I have nginx web server logs with all requests that were made and I'm filtering them by date and time. Each line has the following structure: 127.0.0.1 - xyz.com GET 123.ts HTTP/1.1 (200) 0.000 s 3182 CoreMedia/1.0.0.15F79 (iPhone; U; CPU OS 11_4 like Mac OS X; pt_br) These text files are... (21 Replies)
Discussion started by: brenoasrm
21 Replies

3. Shell Programming and Scripting

How to make awk command faster?

I have the below command which is referring a large file and it is taking 3 hours to run. Can something be done to make this command faster. awk -F ',' '{OFS=","}{ if ($13 == "9999") print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12 }' ${NLAP_TEMP}/hist1.out|sort -T ${NLAP_TEMP} |uniq>... (13 Replies)
Discussion started by: Peu Mukherjee
13 Replies

4. Shell Programming and Scripting

Make script faster

Hi all, In bash scripting, I use to read files: cat $file | while read line; do ... doneHowever, it's a very slow way to read file line by line. E.g. In a file that has 3 columns, and less than 400 rows, like this: I run next script: cat $line | while read line; do ## Reads each... (10 Replies)
Discussion started by: AlbertGM
10 Replies

5. Shell Programming and Scripting

Running rename command on large files and make it faster

Hi All, I have some 80,000 files in a directory which I need to rename. Below is the command which I am currently running and it seems, it is taking fore ever to run this command. This command seems too slow. Is there any way to speed up the command. I have have GNU Parallel installed on my... (6 Replies)
Discussion started by: shoaibjameel123
6 Replies

6. Shell Programming and Scripting

How to make copy work faster

I am trying to copy a folder which contains a list of C executables. It takes 2 mins for completion,where as the entire script takes only 3 more minutes for other process. Is there a way to copy the folder faster so that the performance of the script will improve? (2 Replies)
Discussion started by: prasperl
2 Replies

7. Red Hat

Re:How to make the linux pc faster

Hi, Can any one help me out in solving the problem i have a linux database server it is tooo slow that i am unable to open even the terminial is there any solution to get rid of this problem.How to make this server faster. Thanks & Regards Venky (0 Replies)
Discussion started by: venky_vemuri
0 Replies

8. Shell Programming and Scripting

awk help to make my work faster

hii everyone , i have a file in which i have line numbers.. file name is file1.txt aa bb cc "12" qw xx yy zz "23" we bb qw we "123249" jh here 12,23,123249. is the line number now according to this line numbers we have to print lines from other file named... (11 Replies)
Discussion started by: kumar_amit
11 Replies

9. Shell Programming and Scripting

Can anyone make this script run faster?

One of our servers runs Solaris 8 and does not have "ls -lh" as a valid command. I wrote the following script to make the ls output easier to read and emulate "ls -lh" functionality. The script works, but it is slow when executed on a directory that contains a large number of files. Can anyone make... (10 Replies)
Discussion started by: shew01
10 Replies

10. Solaris

looking for different debugger for Solaris or to make sunstudio faster

im using the sunstudio but it is very slow , is there ant other GUI debugger for sun Solaris or at list some ways to make it faster ? im using to debug throw telnet connection connected to remote server thanks (0 Replies)
Discussion started by: umen
0 Replies
Login or Register to Ask a Question