Hi All,
I need to create a script to look at a very long list of files, and look inside these files for a specific number of a special character "," there needs to be no more than 14 in each line in each file.
I have copied 2 files for testing the script.
dk@server: /export/home/test> ls -alt DK* | awk '{ print $9 }'
DK_TEST2.dat
DK_TEST.dat
dk@server: /export/home/test>
these files look something like this (not exact content, but close - to protect data)
,,30035111,DAVY KELLY JOB NO. 17748000,16940000,04/09/2017,04/09/2017,P001111,10.2,10,1.02,Davy Kelly,1,,
,,30035111,DAVY KELLY JOB NO. 17748000,16940000,04/09/2017,04/09/2017,P001111,13.62,6,2.27,Davy Kelly,2,,
,,30035111,DAVY KELLY JOB NO. 17748000,16940000,04/09/2017,04/09/2017,P029111,16.91,1,16.91,Davy Kelly,3,,
,,30035111,DAVY KELLY JOB NO. 17748000,16940000,04/09/2017,04/09/2017,P029111,16.91,1,16.91,Davy Kelly,4,
I am looking to:
make a list of the filenames in the path that contain DK* save as LIST
for each FILE in LIST
Check via AWK for more than 14 commas - if true print FILENAME to OUTPUT file
mail out OUTPUT file to myself.
#!/bin/sh
###
### Name: check_excesiveComma.sh
### Path: /export/home/test
### Description: Copy a list of Filenames that have more than 14 commas
### Version: 1.1
### Author: DKelly
###
FPATH=/export/home/test
DAT=`date`
MSG=/tmp/email.txt
OUTPUT=/tmp/output.txt
LIST=/tmp/list.txt
touch $LIST
ls -alt DK* | awk '{ print $9 }' >> $LIST
### Change Directory to $FPATH
cd $FPATH
### Check all files for more than 14 commas and output the filenams
for FILE in $LIST
do
if (`awk 'BEGIN -F"," {NF > 14}`) then echo $FILE >> $OUTPUT
done
### Mail out the message and delete the output and message
cat $MSG | /usr/bin/mailx -s"Graftons Files that might cause issues" davy
### remove files.
rm $MSG
rm $LIST
rm $OUTPUT
### end script
Don't worry I know I have a variable for MSG and this is really the one i want to email...
I am not really getting AWK very well... I need to look in the each file in the List, count each line for commas, and echo out the Actual Filename if one of the lines has more than 14 commas.
Please could you kind people point me in the right direction.
davy