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

Solaris


Reply    
 
Thread Tools Search this Thread Display Modes
    #8  
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: 20 November 2017, 10:00 AM EST
Posts: 12
Thanks: 13
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...


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 Unix and Linux 09-14-2017   -   Original Discussion by dakelly
MadeInGermany's Unix or Linux Image
MadeInGermany MadeInGermany is online now Forum Staff  
Moderator
 
Join Date: May 2012
Last Activity: 18 December 2017, 1:37 AM EST
Location: Simplicity
Posts: 3,872
Thanks: 322
Thanked 1,291 Times in 1,168 Posts
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
Reply

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 01: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 12:29 PM
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 10:41 AM
create a shell script that calls another script and and an awk script magikminox Shell Programming and Scripting 0 06-26-2008 03:50 AM



All times are GMT -4. The time now is 03:07 AM.