Awk modification


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk modification
# 8  
Old 05-30-2012
Quote:
Originally Posted by Corona688
So you don't care about the part that does all the g-subbing and splitting for purposes you still haven't disclosed?

Code:
awk 'NR==FNR { S[L++]=$0; next } { M=1; for(N=1; M&&(N<=L); N++) if(!(S[N] ~ $0)) M=0 } M' sfile datafile


please ignore the gsubbing/splitting.

i tested the script, and all it spat out were blank lines.

Code:
awk 'NR==FNR { S[L++]=$0; next } { M=1; for(N=1; M&&(N<=L); N++) if(!(S[N] ~ $0)) M=0 } M' sfile /var/tmp/datafile

i would like to see it spit out the lines it found that matched the strings specified in sfile.

if it would be more straightforward, instead of specifying "sfile", can i just specify the two strings on the command line?

something like this:

Code:
awk 'NR==FNR { S[L++]=$0; next } { M=1; for(N=1; M&&(N<=L); N++) if(!(S[N] ~ $0)) M=0 } M'  '/ERROR/ && /com.rolander.promotions.client/'  /var/tmp/datafile

# 9  
Old 05-30-2012
Smilie

Smilie

Smilie

Code:
awk -v S1="Search1" -v S2="search2" '(S1 ~ $0) && (S2 & $0)' filename

# 10  
Old 05-30-2012
i get this error:

Code:
awk -v S1="ERROR" -v S2="PromotionsWebServiceClient" '(S1 ~ $0) && (S2 & $0)' DATAFILE
awk: (S1 ~ $0) && (S2 & $0)
awk:                  ^ syntax error
awk: cmd. line:1: (S1 ~ $0) && (S2 & $0)
awk: cmd. line:1:                       ^ unexpected newline or end of string


Last edited by SkySmart; 05-30-2012 at 09:56 PM..
# 11  
Old 05-31-2012
Quote:
Originally Posted by Corona688
Code:
awk -v S1="Search1" -v S2="search2" '(S1 ~ $0) && (S2 & $0)' filename

Quote:
Originally Posted by SkySmart
i get this error:
Was already late for corona688Smilie

The var's S1 and S2 need to change position

Code:
awk -v S1="ERROR" -v S2="PromotionsWebServiceClient" '($0 ~ S1) && ($0 ~ S2)' DATAFILE > OUTDATAFILE

This User Gave Thanks to sdf For This Post:
# 12  
Old 05-31-2012
Or?
Code:
grep 'ERROR.*com\.rolander\.promotions\.client' infile

This User Gave Thanks to Scrutinizer For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

cp modification

I'm usia Raspbian, a Debian subset, and wondering what work would be involved in altering the cp command. cp at present needs a full path and file name for source and at least full filename for destination. How can I change this so the second parameter isn't needed? So if the destination... (6 Replies)
Discussion started by: MuntyScrunt
6 Replies

2. Shell Programming and Scripting

Modification to awk command

i have a php file that has this: php.code #!/usr/bin/php <?php phpinfo(); hlight_file(__FILE__); ?> I want my awk code grab whatever is inbetween and including the "<?php" and "?>". Then, it should scan all the entries between these two points. And if the entries between these... (10 Replies)
Discussion started by: SkySmart
10 Replies

3. Shell Programming and Scripting

awk script modification

can someone help me identify what i'm doing wrong here: awk -F'|' 'BEGIN{c=0} /./ && /./ { if ($3 < 2) { print ; c++ } END { print c":OK" } else if (($3 >= 2) && ($3 < 4)) { print ; c++ } END { print c":WARNING" } else if ($3 >= 4) { print ; c++ } END { print c":CRITICAL" } }'... (4 Replies)
Discussion started by: SkySmart
4 Replies

4. Shell Programming and Scripting

awk script modification - treat certain files differently

awk 'BEGIN{OFS=","} FNR == 1 {if (NR > 1) {print fn,fnr,nl} fn=FILENAME; fnr = 1; nl = 0} {fnr = FNR} /UNUSUAL/ && /\.gz/ ~ /FILENAME/ {nl++} <'{system ("gunzip -cd FILENAME")}' END ... (2 Replies)
Discussion started by: SkySmart
2 Replies

5. Shell Programming and Scripting

IP Address Modification through awk/sed

Hi, I have to modify the 2nd and 3rd octet of the IP address through awk/sed. For Example: Given IP is : 10.205.22.254, it should be modified as 10.105.100.254 through awk/sed. Kindly help me on this and let me know if you have any questions. Thanks in advances. (2 Replies)
Discussion started by: kumarbka
2 Replies

6. UNIX for Dummies Questions & Answers

awk output modification

Hello, I am using awk command to print some output, but there are some characters that I would like to remove from the output awk '{print $5$6}' the output I get is column5/:column6 I am looking forward to remove the : and to get the output column5/column6 Sorry if this question is... (4 Replies)
Discussion started by: Error404
4 Replies

7. Shell Programming and Scripting

awk modification for lines

so i have this data in a file: jime=1860,yime=1.23243,lime= jime=1859,yime=1.23018,lime= jime=1825,yime=1.15371,lime= jime=1849,yime=1.20769,lime= jime=1841,yime=1.1897,lime= jime=1849,yime=1.20769,lime= i use this code to calculate the percentage difference of the number in column 2... (9 Replies)
Discussion started by: SkySmart
9 Replies

8. Shell Programming and Scripting

awk script modification

I want the below script to omit every chunk of data that contains a specific hostname. here's the scenario. i have a configuration file that contains the configuration of several hosts. a sample of this configuration file is this: define host { address ... (12 Replies)
Discussion started by: SkySmart
12 Replies

9. Shell Programming and Scripting

in line modification in a file using awk

Hi, I have a conf.file with the following values: ef=78 b=40 ca=40 c=45/dev2 when I modify one of the line with the below awk script,it's modifying BUT it's placing the modified line in the last line : input:- Configure b 45/dev4 output:- ef=78 ca=40 ... (2 Replies)
Discussion started by: axes
2 Replies

10. UNIX for Advanced & Expert Users

Swap modification

How can i modify (expand) the swap memory (Sco Enterprise 5.0.5) using the swap command...? The excisting swap is 512 and i want to increase it to 1024...? Thanx in advance (2 Replies)
Discussion started by: psychofredy
2 Replies
Login or Register to Ask a Question