scanning the file for a particular column


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers scanning the file for a particular column
# 8  
Old 01-11-2011
Code:
awk '$4 {...}

means if "$4" exists and is not zero (in which case e would be set to 1, etc.).

I suppose $4 != 0 would have done the same (assuming $4 existed).
# 9  
Old 01-11-2011
Hey, I am not an awk-ie, but I read "if field 4 is true (not zero, like in C) then print problem, set a variable e to 1 and (see above) go to END. The rest says if variable e not set to 1, print fine. Being an awk doofus, I wonder if it prints fine a lot or if the curly braces or something says call me at eof. If I hang around here too much, I will speak awk by oooozemosis. Smilie
# 10  
Old 01-11-2011
Smilie Careful, or you might even turn into an awk-ie unknowingly, now that would be sed wouldn't it Smilie
# 11  
Old 01-11-2011
Code:
 awk '$4{f=1;exit}END{ print f?"problem":"fine"}' file

# 12  
Old 01-12-2011
How does that improve on #3?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Scanning a pdf file in Linux shell

I want to search a keyword in a list of pdf files and when i find a match i want to write the title and author of that pdf file to another file. How will I do this using linux shell script? (7 Replies)
Discussion started by: SK33
7 Replies

2. Shell Programming and Scripting

Reg scanning time based log file

Hi, I have a requirement to scan Oracle's alert log file. This file logs all event for Oracle database and each line will have timestamp followed by messages (which might be one or more lines). Example. Thu Aug 15 17:35:59 2013 VKTM detected a time drift. Please check trace file for more... (1 Reply)
Discussion started by: manickaraja
1 Replies

3. Shell Programming and Scripting

[Solved] Sorting a column in a file based on a column in a second file

Hello, I have two files as the following: File1: F0100020 A G F0100030 A T F0100040 A G File2: F0100040 A G BTA-28763-no-rs 77.2692 F0100030 A T BTA-29334-no-rs 11.4989 F0100020 A G BTA-29515-no-rs 127.006 I want to sort the second file based on the... (6 Replies)
Discussion started by: Homa
6 Replies

4. Shell Programming and Scripting

Awk: Need help replacing a specific column in a file by part of a column in another file

Hi, I have two input files as File1 : ABC:client1:project1 XYZ:client2-aa:project2 DEF:client4:proj File2 : client1:W-170:xx client2-aa:WT-04:yy client4:L-005A:zz Also, array of valid values can be hardcoded like Output : ABC:W:project1 XYZ:WT:project2 (1 Reply)
Discussion started by: aa2601
1 Replies

5. Shell Programming and Scripting

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2 file 1 sample SNDK 80004C101 AT XLNX 983919101 BB NETL 64118B100 BS AMD 007903107 CC KLAC 482480100 DC TER 880770102 KATS ATHR 04743P108 KATS... (7 Replies)
Discussion started by: rydz00
7 Replies

6. Shell Programming and Scripting

Changing one column of delimited file column to fixed width column

Hi, Iam new to unix. I have one input file . Input file : ID1~Name1~Place1 ID2~Name2~Place2 ID3~Name3~Place3 I need output such that only first column should change to fixed width column of 15 characters of length. Output File: ID1<<12 spaces>>Name1~Place1 ID2<<12... (5 Replies)
Discussion started by: manneni prakash
5 Replies

7. Shell Programming and Scripting

To cut entire column from a file and apend it to another file as another column

file1.txt : india pakistan bangladesh japan canada africa USA srilanka Nepal file2.txt Delhi Tokyo washington I have to cut the first column of file1.txt and apend it with file2.txt as another column like this Delhi india Tokyo japan washington USA ... (4 Replies)
Discussion started by: sakthifire
4 Replies

8. UNIX for Advanced & Expert Users

Scanning file backwards

Is there any way to look for a directory path that is listed any number of lines *before* a keyword in an error message? I have a script that is trying to process different files that are always down a certain portion of a path, and if there is an error, then says there is an error, contact... (2 Replies)
Discussion started by: tekster757
2 Replies

9. Shell Programming and Scripting

How to zip a modified file 15 days before but not scanning my sub directory files

I am using zip -m option to zip my files, but i dont want my sub directories files to be zipped (1 Reply)
Discussion started by: skrish70
1 Replies

10. Shell Programming and Scripting

scanning for '0' value in .txt file

Hello I am a novice shell scripting programmer, so please bare with me. I have embedded a simple SQL statement into a shell script, which simply returns an integer (its a count (*) statement). The result of the statement is then oputput to .txt file. So, the number could be 0, 1,2, 10,... (4 Replies)
Discussion started by: man80
4 Replies
Login or Register to Ask a Question