Unix/Linux Go Back    

Solaris The Solaris Operating System, usually known simply as Solaris, is a Unix-based operating system introduced by Sun Microsystems. The Solaris OS is now owned by Oracle.

Help with Script using awk


Thread Tools Search this Thread Display Modes
Old Unix and Linux 09-08-2017   -   Original Discussion by dakelly
dakelly's Unix or Linux Image
dakelly dakelly is offline
Registered User
Join Date: May 2017
Last Activity: 9 March 2018, 10:48 AM EST
Posts: 15
Thanks: 16
Thanked 1 Time in 1 Post
Hi All,

Amazing what a wee nights sleep can do....

I found my issue was trying awk in the if statement, so changed it and amended it to what I need...

. . .
LIST=`ls -1 POM* 2>/dev/null`
. . .

for FILE in $LIST
    awk -F"," ' { if( NF > 14){ print FILENAME" line:> " NR }}' $FILE >> $OUTPUT

this work perfect for what I need it for...

Thanks for all your suggestions.


P.s. Yes still on Solaris 10 but moving to 11 later in the year.
Sponsored Links
Old Unix and Linux 09-14-2017   -   Original Discussion by dakelly
MadeInGermany's Unix or Linux Image
MadeInGermany MadeInGermany is offline Forum Staff  
Join Date: May 2012
Last Activity: 22 March 2018, 10:49 PM EDT
Location: Simplicity
Posts: 4,010
Thanks: 343
Thanked 1,346 Times in 1,214 Posts
If you do not use $LIST elsewhere you can do

. . .
. . .

for FILE in POM*
    [ -f "$FILE" ] || continue
    awk -F"," '{ if (NF > 14) { print FILENAME" line:> " NR } }' "$FILE"
done > $OUTPUT

The whole output stream is redirected to $OUTPUT, this is more efficient than many times append it.
The globbing in the for requires a test to ensure presence, but the test also ensures that it's a real file (not a directory) which makes it more robust.
Have $FILE in quotes, or the shell attempts to expand it.
The Following User Says Thank You to MadeInGermany For This Useful Post:
dakelly (10-02-2017)
Sponsored Links

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Shell script works fine as a standalone script but not as part of a bigger script ektubbe Shell Programming and Scripting 2 07-11-2017 12:13 PM
Calling a script from master script to get value from called script Raj Roy UNIX for Dummies Questions & Answers 2 03-14-2014 11:29 AM
Script will keep checking running status of another script and also restart called script at night ketanraut Shell Programming and Scripting 1 11-20-2013 09:41 AM
create a shell script that calls another script and and an awk script magikminox Shell Programming and Scripting 0 06-26-2008 02:50 AM

All times are GMT -4. The time now is 01:30 AM.