If field 12 = NO then


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting If field 12 = NO then
# 8  
Old 10-08-2014
I agree with blackrageous. I am having trouble trying to figure out what you're trying to do.

You say that you want to find lines with field 12 having value No, but you show us a grep looking for 716780068810201413130@192.168.155.2???

You say that you have thousands of .csv files with the following naming convention BW*2014*.csv, but all of the files you have shown us seem to have names that end with .log; not .csv??? In fact, the name of the file containing the data you showed us in your 1st post seems to be BW-CDR-20140102072500-2-AC162DB137C8-087691-000.csv_rejected_6087016-20141007220203.log:BW-CDR-20140102072500-2-AC162DB137C8-087691-000.csv_rejected_6087016-20141007220203.log:BW-CDR-20140102072500-2-AC162DB137C8-087691-000.csv_rejected_6087016-20141007220203.log:BW-CDR-20140102072500-2-AC162DB137C8-087691-000.csv_rejected_6087016-20141007220203.log:BW-CDR-20140102072500-2-AC162DB137C8-087691-000.csv_rejected_6087016-20141007220203.log:BW-CDR-20140102072500-2-AC162DB137C8-087691-000.csv_rejected_6087016-20141007220203.log:BW-CDR-20141008130500-2-AC162DB137C8-168113-000.csv_rejected_6090130-20141008132313.log although it could cut off at any of the colons in that string; but there is no way that the name ends in .csv.

Please give us a consistent description of what you're trying to do and show us sample input and output data that aligns with that description!
# 9  
Old 10-08-2014
@Kibou
Please note first command returns exit code 2 soon after reading first line of input file, and it comes directly to END block.
This User Gave Thanks to Akshay Hegde For This Post:
# 10  
Old 10-09-2014
Thank you Akshay Hedge.

I also tried it also outside the BEGIN block but it didn't work to me. It does work so I obviously did something wrong.

And thank you for the explanation as well.

Last edited by Kibou; 10-09-2014 at 05:22 AM.. Reason: Tags added
# 11  
Old 10-09-2014
Quote:
Originally Posted by Kibou
Thank you Akshay Hedge.

I also tried it also outside the BEGIN block but it didn't work to me. It does work so I obviously did something wrong.

And thank you for the explanation as well.
You can do something like this

Code:
[akshay@nio tmp]$ awk -F, 'BEGIN{f1=f2=0}FNR==NR{if($12 != "No")f1++; next}{f2++}END{print f1,f2}' file file
3 10

[akshay@nio tmp]$ awk -F, 'BEGIN{f1=f2=0}FNR==NR{if($12 != "No")f1++; next}{f2++}END{exit (f1==f2)?0:1}' file file; echo $?
1

It returns exit code zero if both f1 and f2 are equal meaning there is no No in field $12
This User Gave Thanks to Akshay Hegde For This Post:
# 12  
Old 10-09-2014
Oh, you used the same file for the explanation!

I've just come up with something like this

Code:
kibou@laptop:~$ awk -F, '$2 == "e" {f=3} END{exit f}' file ; echo $?
3
kibou@laptop:~$ cat file
a,b,c
d,e,f
g,h,i

so I'm testing my understanding of exit at the END block.

Thanks so much.
# 13  
Old 10-10-2014
You guys are amazing. My solution is working like clock work thank you for helping.
This is the route that i took below:
Code:
grep "Y,Unknown scenario:BST" BW*2014* > Accntfound.csv
sed -i '/Y,Unknown scenario:BST/d' BW*2014*
awk 'BEGIN{FS=","} $12 != "No"' Accntfound.csv > yes_output.csv
awk 'BEGIN{FS=","} $12 != "Yes"' Accntfound.csv > no_output.csv
cat yes_output.csv >> $(ls -ltr BW* | awk 'END{print $9}')
cat no_output.csv >> Unanswered_Calls.csv
rm yes_output.csv Accntfound.csv no_output.csv

This User Gave Thanks to kekanap For This Post:
# 14  
Old 10-10-2014
I am glad it helped, but does it work?

This line complains using the sample you gave to us in the beginning

Code:
cat yes_output.csv >> $(ls -ltr BW* | awk 'END{print $9}')

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Problem with getting awk to multiply a field by a value set based on condition of another field

Hi, So awk is driving me crazy on this one. I have searched everywhere and read man, docs and every related post Google can find and still no luck. The actual files I need to run this on are sensitive in nature, but it is the same thing as if I needed to calculate weighted grades for multiple... (15 Replies)
Discussion started by: cotilloe
15 Replies

2. Shell Programming and Scripting

awk to update field using matching value in file1 and substring in field in file2

In the awk below I am trying to set/update the value of $14 in file2 in bold, using the matching NM_ in $12 or $9 in file2 with the NM_ in $2 of file1. The lengths of $9 and $12 can be variable but what is consistent is the start pattern will always be NM_ and the end pattern is always ;... (2 Replies)
Discussion started by: cmccabe
2 Replies

3. Shell Programming and Scripting

awk to adjust coordinates in field based on sequential numbers in another field

I am trying to output a tab-delimited result that uses the data from a tab-delimited file to combine and subtract specific lines. If $4 matches in each line then the first matching sequential $6 value is added to $2, unless the value is 1, then the original $2 is used (like in the case of line... (3 Replies)
Discussion started by: cmccabe
3 Replies

4. Shell Programming and Scripting

Display combination of 4 field uniqe record and along with concatenate 5th and 6th field.

Table ACN|NAME|CITY|CTY|NO1|NO2 115|AKKK|ASH|IND|10|15 115|AKKK|ASH|IND|20|20 115|AKKK|ASH|IND|30|35 115|AKKK|ASH|IND|30|35 112|ABC|FL|USA|15|15 112|ABC|FL|USA|25|20 112|ABC|FL|USA|25|45 i have written shell script using cut command and awk programming getting error correct it and add... (5 Replies)
Discussion started by: udhal
5 Replies

5. Shell Programming and Scripting

Command/script to match a field and print the next field of each line in a file.

Hello, I have a text file in the below format: Source Destination State Lag Status CQA02W2K12pl:D:\CAQA ... (10 Replies)
Discussion started by: pocodot
10 Replies

6. Linux

How do I format a Date field of a .CSV file with multiple commas in a string field?

I have a .CSV file (file.csv) whose data are all enclosed in double quotes. Sample format of the file is as below: column1,column2,column3,column4,column5,column6, column7, Column8, Column9, Column10 "12","B000QRIGJ4","4432","string with quotes, and with a comma, and colon: in... (3 Replies)
Discussion started by: dhruuv369
3 Replies

7. Shell Programming and Scripting

Plz Help. Compare 2 files field by field and get the output in another file.

Hi Freinds, I have 2 files . one is source.txt and second one is target.txt. I want to keep source.txt as baseline and compare target.txt. please find the data in 2 files and Expected output. Source.txt 1|HYD|NAG|TRA|34.5|1234 2|CHE|ESW|DES|36.5|134 3|BAN|MEH|TRA|33.5|234... (5 Replies)
Discussion started by: i150371485
5 Replies

8. Shell Programming and Scripting

AWK: Pattern match between 2 files, then compare a field in file1 as > or < field in file2

First, thanks for the help in previous posts... couldn't have gotten where I am now without it! So here is what I have, I use AWK to match $1 and $2 as 1 string in file1 to $1 and $2 as 1 string in file2. Now I'm wondering if I can extend this AWK command to incorporate the following: If $1... (4 Replies)
Discussion started by: right_coaster
4 Replies

9. Shell Programming and Scripting

awk, comma as field separator and text inside double quotes as a field.

Hi, all I need to get fields in a line that are separated by commas, some of the fields are enclosed with double quotes, and they are supposed to be treated as a single field even if there are commas inside the quotes. sample input: for this line, 5 fields are supposed to be extracted, they... (8 Replies)
Discussion started by: kevintse
8 Replies

10. Shell Programming and Scripting

Sort alpha on 1st field, numerical on 2nd field (sci notation)

I want to sort alphabetically on the first field and sort in descending numerical order on the 2nd field. With a normal "sort -r -n" it does this: abc ||| 5e-05 ||| bla abc ||| 3 ||| ble def ||| 1 ||| abc def ||| 0.2 ||| def As you can see it ignores the fact that 5e-05 is actually 0.00005... (1 Reply)
Discussion started by: FrancoisCN
1 Replies
Login or Register to Ask a Question