LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-12-2011, 06:40 AM   #1
papori
LQ Newbie
 
Registered: Feb 2011
Posts: 23

Rep: Reputation: 0
printing file name , when using awk


Hey all,
i am going throw all files in directory and want to print the files that having more than 1 "%" in their content...
what should i exchange in BOLD?

for file in * ;
do awk -F'(%)' '{ t += (NF - 1) } END
{if (t>1) print $file ;}'
$file;done

thanks!
 
Old 07-12-2011, 08:27 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,437

Rep: Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842
Well my first question would be why bother with the for loop?
Code:
awk '/%/ && ++i > 1{print FILENAME;i=0;nextfile}' *
Of course if there are directories in there as well as files this will error
 
Old 07-12-2011, 12:14 PM   #3
papori
LQ Newbie
 
Registered: Feb 2011
Posts: 23

Original Poster
Rep: Reputation: 0
execp with awk

Hey all,
i am trying to write a bash command that checking in the whole directory if any file contain more than 1 "%".
if ןi found , i want to run an outer program from other directory.
the input of the outer program is the file that have more than 1 %.
i was trying to use execp, but the program dont know the files.

Moreover, i want the output name will be as the input name + *.out

how to do this?

for file in * ;
do awk -F'(>)' '{ t += (NF - 1) } END {if (t>1)
/path_to_PROGRAM -i $input -o output;}' $file;done


thanks
 
Old 07-12-2011, 12:37 PM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Two similar threads merged here. Please, keep discussion in one place. Thank you.
 
Old 07-12-2011, 12:44 PM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Following the suggestion by grail above:
Code:
awk -F'%' '{t += (NF - 1)} {if (t > 1) {print "/path/to/program -i",FILENAME,"-o",FILENAME ".out" | "/bin/bash"; t = 0; nextfile}}' *
 
  


Reply


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
[SOLVED] printing array in awk ghantauke Linux - Newbie 3 11-24-2010 09:16 AM
How to use awk for printing line from database? trustmeajay Linux - Software 1 07-22-2010 08:44 PM
printing multiple columns with awk kdelover Programming 16 12-16-2009 09:10 AM
help needed in awk printing ZAMO Linux - General 1 01-30-2009 03:00 AM
awk column printing schneidz Programming 7 09-29-2005 06:14 AM


All times are GMT -5. The time now is 10:40 AM.

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