Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 12-04-2011, 08:45 AM   #1
Registered: Jul 2007
Location: Bucharest, Romania
Distribution: Ubuntu
Posts: 42

Rep: Reputation: 0
awk return an error that I don't know how to handle

Hello everyone,

I have an nasty message that I receive all the time and I have no idea how to cope with.
My application is to make a script that finds directories where there are lots and lots of files, which eat a lot of inodes, in order to delete them.
For this I used a simple "find / -name "*" -fls listfile.txt -type f" that writes to listfile.txt all normal files existing in the system.
After this I separate the last column that represent the full path to files (in the file intermediar.txt) and try to use them with awk. Whatever i try to do i get this error:

awk '{ printf ""$0"\n" }' intermediar.txt >> int2
awk: (FILENAME=intermediar.txt FNR=465244) fatal: not enough arguments to satisfy format string
^ ran out for this one

Any idea? I really need to use awk for this one. I tried different tricks with sed, but i am limited.

Thank you.
Old 12-04-2011, 08:56 AM   #2
David the H.
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,837

Rep: Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981
printf ""$0"\n"
This is not the proper syntax for an awk printf statement. The first argument needs to be the format string, followed by a comma, and then the input string to be formatted.

printf "%s\n" , $0
Of course the above format string is just equal to the print command.

What is it exactly that you want the awk command to do, anyway? Could you give us an actual example of the input and desired output?

Finally, please use [code][/code] tags around your code and data, to preserve formatting and to improve readability.
1 members found this post helpful.
Old 12-08-2011, 04:34 PM   #3
Registered: Jul 2007
Location: Bucharest, Romania
Distribution: Ubuntu
Posts: 42

Original Poster
Rep: Reputation: 0

Yes I will post the whole thing I intend awk to do, and explain the idea in full detail.

Thank you David.
Old 12-09-2011, 11:15 AM   #4
Registered: Jul 2007
Location: Bucharest, Romania
Distribution: Ubuntu
Posts: 42

Original Poster
Rep: Reputation: 0


Sorry for not being explicit from the start. Here is what I have to do:

I work on Unix based servers (I know this post should be under Unix/Solaris etc. but it's general thing, and my chances are higher here), and there are processes that periodically generate log files. The thing is that often there is no purging entry in crontab to automatically delete the old and obsolete files. This of course, in time even though there is plenty of space on HDD, eats all inodes, meaning no write can be done anymore (not to mention the very slow OS when this happens). So I made up a script to identify where exactly the folder containing lots and lots of files is located in order to further investigate. The script work just fine, but it is totally memory inefficient(so I need awk to replace part of it). Downwards is the script:


echo "Start first phase. This will take a while ..."
find / -name "*" -type f -fls result.txt
# this phase literally searches all files on root file system and dumps full path to each one of them in result.txt. No fancy things here, just a find command
echo "First phase done. Second phase is starting. It also will take a while ..."
sed 's/^.*[0-9][0-9] \(\/.*\)\/.*$/\1/g' result.txt >> intermediar.txt
# the sed command here retains only the directory to where the file is situated. I used some regex to describe the pattern encountered on each line
echo "Last phase. Results are shown downwards:"
printf "\n\n\n\n"

#from now on what's done is a simple count of each occurrence of a distinct path (since in case a folder contains 100000 text files each file is printed
with it's full path in result.txt, it means that the path appears 100000 times in this file ... so it is counted). The thing is that the script accepts an
input variable which is the minimum number of files a folder should contain in order to be displayed.
#Well, what I need is to replace this counting part of the script with something awk based. I tried different approaches but failed. Indeed I should read
carefully the awk manual, but I ask for help this time, as i don't have sufficient time to improve my awk skills.
#Thank you in advance.

rm result.txt
for i in $(cat intermediar.txt)
if [[ $var == $var1 ]]
if (( $min_val <= $suma ));then
echo "$suma ---> $var"
printf "\n"


The thing with this script is that at third phase when loading all lines of result.txt "for i in $(cat intermediar.txt)" , the memory it eats goes of the scale, and for a server this is the last thing anyone would want.

Thank you in advance for your help

Last edited by coss_cat; 12-09-2011 at 11:17 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to handle division by zero in awk dazdaz Programming 2 05-29-2011 08:15 PM
Limit in number of fields that awk can handle ? chargaff Programming 4 03-03-2011 09:36 AM
dpkg return error :post installation script return an error code (1) grimfold Debian 2 09-10-2009 02:55 PM
awk: How can I return a specified record dimsh Linux - Newbie 4 09-24-2005 12:36 PM
How to return values into an array using awk Helene Programming 1 05-01-2004 11:05 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:04 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration