Updated files information


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Updated files information
# 1  
Old 10-18-2012
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.

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
rm -f $srcfile
mv $tgtfile $srcfile
done<sample_txt_files
rm -f sample_txt_files
echo "completed"


Last edited by Corona688; 10-18-2012 at 03:57 PM..
# 2  
Old 10-18-2012
try this...

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"

I have tried using single awk.. but getting below error..


Code:
awk -F, -v file="file_name" '$3 =="" {if(!x[file]){print file > test_temp};next}1' file1
foo1,good,dsd,sfdf
awk: (FILENAME=file1 FNR=2) fatal: expression for `>' redirection has null string value

# 3  
Old 10-18-2012
its working thanks boss...
# 4  
Old 10-19-2012
Code:
 
awk -F, '$3==""{a[FILENAME]++}END{for(i in a)print i}' CUSTADDR*.txt

awk has the in-built variable called FILENAME

The above command will show the files which has
# 5  
Old 10-19-2012
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 Scott; 10-19-2012 at 05:00 PM.. Reason: Code tags, chief!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Comparing two files to get only records to be inserted and updated

Hello all, Please help me for a script that compares two files and reads only those records that are to be inserted and updated. File1: c_id name place contact_no 1 abc xyz 34567 10 efg uvw 82725 6 hjk wth 01823 2 iuy ... (4 Replies)
Discussion started by: T@ni@
4 Replies

2. 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

3. Shell Programming and Scripting

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 #!/usr/bin/sh Scripts=/ushhquest/data001/Scripts cd... (5 Replies)
Discussion started by: katakamvivek
5 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