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

👤 Login to reply

    #8  
Old 09-08-2017
dakelly dakelly is offline
Registered User
 
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...

Code:
. . .
OUTPUT=/tmp/output.txt
LIST=`ls -1 POM* 2>/dev/null`
. . .

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

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

Thanks for all your suggestions.

davy

P.s. Yes still on Solaris 10 but moving to 11 later in the year.
Sponsored Links
    #9  
Old 09-14-2017
MadeInGermany MadeInGermany is online now Forum Staff  
Moderator
 
If you do not use $LIST elsewhere you can do
Code:
. . .
OUTPUT=/tmp/output.txt
. . .

for FILE in POM*
do
    [ -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
👤 Login to reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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:46 PM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
×
UNIX.COM Login
Username:
Password:  
Show Password





Not a Forum Member?
Forgot Password?