Check file from multiple files is empty using awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Check file from multiple files is empty using awk
# 8  
Old 07-31-2015
Quote:
Originally Posted by siramitsharma
Yup, changed in the code but didn't updated in the code shared by you.
... ... ...
---------- Post updated at 12:30 PM ---------- Previous update was at 11:47 AM ----------

Hi Don, also if you see that file4 content, i am putting field1 in array whose value is field2 from file4
Code:
filecounter==4{UPW[$1]=$2;next}

& the same is being matched from mainfile. I have also highlighted the same in my earlier post. Can you please suggest how to handle this.
I understand that your code is setting values in your four arrays that are never used. If you change the four lines setting the arrays from:
Code:
filecounter==1 {KRL[$1]=$2;next}
...

to:
Code:
filecounter==1 {KRL[$1];next}
...

you would get exactly the same results. I left that seemingly extraneous initialization in place assuming that your real code would do something with the values that had been saved in the arrays instead of just saying "FOUND IN arrayname".

But I have no idea what "this" is referring to in:
Quote:
Can you please suggest how to handle this.
Please explain what you are trying to change and show us what output you are trying to produce.
# 9  
Old 07-31-2015
Quote:
Originally Posted by gwillie
Taken from stackoverflow.com/questions/24535753

Code:
awk 'END{print(NR>2)?"NOT EMPTY":"EMPTY"}'

You must put this part in END block otherwise it'll be executed for every line.
I do not see how this is related to this thread??? Adding this END clause to the code being used in this thread will print "NOT EMPTY" if at least one of the five files being processed by these scripts is not empty, and will print "EMPTY" if there are no lines in any of the five input files.

Sorry, I should have gotten more sleep last night. Ignore what I said above...
I do not see how this is related to this thread??? Adding this END clause to the code being used in this thread will print "NOT EMPTY" if at least two lines were found in the five files being processed by these scripts, and will print "EMPTY" if there are less than three lines in all of the five input files combined.

Last edited by Don Cragun; 07-31-2015 at 09:03 AM.. Reason: Fix bad description...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How can I check, if on remote server directory is empty or have files?

I have a script, which is supposed to run 1 day of the month, connect to remote server certain directory, find files, tar the, and copy find . -ctime -1 | tar -cvf transfer_dmz_start_monthly.tar *${Today}*.*; if then echo "Cannot create a tar file, the terminated... (2 Replies)
Discussion started by: digioleg54
2 Replies

2. UNIX for Beginners Questions & Answers

Creating multiple empty files with touch

Hello, sorry to bother anyone reading this I have an assignment with a question that reads: Your current directory is stenton. Create empty files called f1, f2, and f12 (in that order), within stenton So my first thought was to enter: touch f1 f2 f12 but that does not work, does anyone... (1 Reply)
Discussion started by: eleuin
1 Replies

3. UNIX for Beginners Questions & Answers

Split file into multiple files based on empty lines

I am using below code to split files based on blank lines but it does not work. awk 'BEGIN{i=0}{RS="";}{x="F"++i;}{print > x;}' Your help would be highly appreciated find attachment of sample.txt file (2 Replies)
Discussion started by: imranrasheedamu
2 Replies

4. Shell Programming and Scripting

Empty file check

Hi gurus , I have two files and i want to perform different action based on the condition if both or either is empty If then Do something elif then do something elif then do something else do something fi I have tried the below bt its not... (4 Replies)
Discussion started by: r_t_1601
4 Replies

5. Shell Programming and Scripting

File check script fails for multiple files

I want to check if any file with testing*.txt exists but my script fails if more than 1 file exists. It works fine for a single file if then echo "TEST21" fi -------------- bash: How do I fix this? Thanks Please use code tags next time for your code and data. (8 Replies)
Discussion started by: sumang24
8 Replies

6. Shell Programming and Scripting

Empty out multiple files with a single command?

I have a log directory: /logs/foo.log /logs/bar.log /logs/err.out I'm trying to find a way to > /logs/*.log > /logs/*.out to blank them out, but of course, that doesn't work. Any suggestions? (4 Replies)
Discussion started by: Validatorian
4 Replies

7. Shell Programming and Scripting

Empty Multiple files contents

I would like to empty multiple files contents (without delete the file) which have similar name to begin with. e.g. log1.txt log2.txt log3.txt log4.txt I know cat /dev/null will do the job but that only apply to a single file. But when i tried cat /dev/null > {} \; that doesnt do... (7 Replies)
Discussion started by: kin
7 Replies

8. Shell Programming and Scripting

Check if a text file is empty or not (using ls -s)

Hello, I want to make a script which says if a text file is empty or not. I tried two ways of making it, but I have problems with both of them. Now I think that the better way is the ls -s solution (considering that an empty text file has a 0 weight, because "cat file.txt" fails when file is... (4 Replies)
Discussion started by: Link_
4 Replies

9. Shell Programming and Scripting

check if file is empty

How do I check if a file is empty in a sh script I want to test in my shell script if the output file is empty and if it is do one thing and if it isnt empty do another? any ideas? (8 Replies)
Discussion started by: stolz
8 Replies

10. UNIX for Dummies Questions & Answers

How to check if a file is empty?

Hi Masters..... I have problem !!! I need to check number of records in a file and if it is zero or file is empty i need to do some task. if ; then echo "File s empty" else echo "Not empty" fi so how to check this condition. I used wc -l < filename.txt => 1 for zero records same result... (1 Reply)
Discussion started by: shreekrishnagd
1 Replies
Login or Register to Ask a Question