Updated files using awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Updated files using awk
# 1  
Old 10-19-2012
Updated files using awk

If third column contains null value then it should delete the row and i want to know the files which contains null value in 3rd column.Below code is not showing the updated files correctly..not sure what the issue is.plz help me

Code:
#!/usr/bin/sh
Scripts=/ushhquest/data001/Scripts

cd /ushhquest/data011/TgtFiles/MonthlyData
ls CUSTADDR*.txt > sample_txt_files
while read line
do
srcfile="/ushhquest/data012/TgtFiles/BMMonthlyData"$line
tgtfile=/ushhquest/data012/TgtFiles/BMMonthlyData/output.txt
awk -F, '$3 =="" {next;}1' $srcfile >> $tgtfile
if [[ $(awk -F, '$3 =="" {print;exit}' $srcfile) ]]
then
echo $srcfile >> output_file # Here you get all the files which has $3 blank
fi
#rm -f $srcfile # You don't need rm here...
mv $tgtfile $srcfile
done<sample_txt_files
rm -f sample_txt_files
echo "completed"


Last edited by Franklin52; 10-20-2012 at 12:04 PM.. Reason: Please use code tags
# 2  
Old 10-19-2012
Modification:-

Code:
if [ $(awk -F, '$3 =="" {print;exit}' $srcfile) ]; then
 echo $srcfile >> output_file
fi


Last edited by Yoda; 10-20-2012 at 12:12 PM..
# 3  
Old 10-19-2012
also try replacing:
Code:
if [[ $(awk -F, '$3 =="" {print;exit}' $srcfile) ]]
then
echo $srcfile >> output_file # Here you get all the files which has $3 blank
fi

with:
Code:
awk -F, '$3 =="" {print FILENAME;exit}' $srcfile >> output_file

# 4  
Old 10-19-2012
Getting error as :Syntax error at line 12: ']]' is not expected.when using below code

Code:
if [[ $(awk -F, '$3 =="" {print;exit}' $srcfile) ]]
then
echo $srcfile >> output_file # Here you get all the files which has $3 blank
fi

---------- Post updated at 03:33 PM ---------- Previous update was at 03:32 PM ----------

Code:
if [ $(awk -F, '$3 =="" {print;exit}' $srcfile) ]; then
 echo $srcfile >> output_file
fi

not showing correct file names.

---------- Post updated at 03:34 PM ---------- Previous update was at 03:33 PM ----------

awk -F, '$3 =="" {print FILENAME;exit}' $srcfile >> output_file.where i want to replace the line from below code.
Code:
#!/usr/bin/sh
Scripts=/ushhquest/data001/Scripts

cd /ushhquest/data011/TgtFiles/MonthlyData
ls CUSTADDR*.txt > sample_txt_files
while read line
do
srcfile="/ushhquest/data012/TgtFiles/BMMonthlyData"$line
tgtfile=/ushhquest/data012/TgtFiles/BMMonthlyData/output.txt
awk -F, '$3 =="" {next;}1' $srcfile >> $tgtfile
if [[ $(awk -F, '$3 =="" {print;exit}' $srcfile) ]]
then
echo $srcfile >> output_file # Here you get all the files which has $3 blank
fi
#rm -f $srcfile # You don't need rm here...
mv $tgtfile $srcfile
done<sample_txt_files
rm -f sample_txt_files
echo "completed"

Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Image

Last edited by vgersh99; 10-19-2012 at 06:00 PM.. Reason: code tags, please!
# 5  
Old 10-19-2012
Quote:
Originally Posted by katakamvivek
not showing correct file names.
Not showing correct files means what....???

Which file names you want $srcfile or $tgtfile ???
# 6  
Old 10-20-2012
Sorry for the confusion boss ,I did mistake while copying the code ....thanks for your help
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help needed to print the not updated files in the Directory

Hi All, I have written one program to print the files which are not updated in the specified directory in .Dat file. If I am executing the same command in the command prompt its working fine but if I am executing in shell script it's not working fine. Please correct if any thing wrong in the... (3 Replies)
Discussion started by: bbc17484
3 Replies

2. Shell Programming and Scripting

Updated files information

I am using the below script to remove the rows which contains null values in the 3rd column.My requirement here is want to get the filenames which row is removed .please help me. #!/usr/bin/sh Scripts=/ushhquest/data001/Scripts cd /ushhquest/data011/TgtFiles/MonthlyData ls CUSTADDR*.txt >... (4 Replies)
Discussion started by: katakamvivek
4 Replies

3. Shell Programming and Scripting

Find out whether directory has been updated with files in the last 5 minutes or not

Hi, I am trying to work on this script that needs to monitor a Directory. In case there are no files received in that Directory for the last 5 minutes, it has to send out an alert. Could someone please suggest any approach for the same. Note: I did check out various previous psts -... (8 Replies)
Discussion started by: rituparna_gupta
8 Replies

4. Shell Programming and Scripting

Copying updated files

I have a directory with source code and want to figure out the files whose content has changed. Suppose I have two version of development work called hstmy.1.0 and hstmy.1.7. Directory structure are basically the same. However there may be additional files and directories, whose contents... (5 Replies)
Discussion started by: kristinu
5 Replies

5. UNIX for Dummies Questions & Answers

How do crontab files get updated with changes?

I have an ant script that puts my crontabtemplate changes out on a solaris server. But I am scratching my head trying to figure out what to do next on getting the actual crontab file updated with changes. Somone have suggestions on reads or links to figure this out? thx in advance (2 Replies)
Discussion started by: vsekvsek
2 Replies

6. Shell Programming and Scripting

Old time stamp being updated for new files

Hello Friends I am facing a weird problem :confused:, we receive thousands of files in my system on a daily basis, access time stamp on some of the files are being updated as old time stamp like 1968-01-19, Could some one help me what could be causing this? so that i can narrow down the problem... (4 Replies)
Discussion started by: Prateek007
4 Replies

7. Shell Programming and Scripting

Find last updated files and rename

HI I have a requirement to find the last updated files from a directory whcih has subdirectories and inside them we have files with .txt,.doc,.xls .. extensions. i have to find those files which were updated in the last 1hr and rename the files with respective <sub-directory>_<filename> and copy... (3 Replies)
Discussion started by: ramse8pc
3 Replies

8. Shell Programming and Scripting

to find the last updated file from different groups of files.

Hi i have many sets of files as shown below(here i have shown 2 sets) basel_aa_20091030.txt basel_aa_20091130.txt basel_aa_20091230.txt basel_bb_20091030.txt basel_bb_20091130.txt basel_bb_20091230.txt from each set of files i need to select the latest updated file(there are... (3 Replies)
Discussion started by: jagadeeshn04
3 Replies

9. Solaris

files updated in last 10 hours should be moved

Hi, I would like to move all files that are updated in last 10 hrs. to some temporary folder. Please help. (3 Replies)
Discussion started by: sanjay1979
3 Replies

10. UNIX for Dummies Questions & Answers

recently updated files

How do I find files those have been updated in the last 24 hours, sort them by size descending and then display the top of the long list? (6 Replies)
Discussion started by: shantanuo
6 Replies
Login or Register to Ask a Question