user2663468
user2663468

Reputation: 85

Unique file names in a directory in unix

I have a capture file in a directory in which some logs are being written in a file

word.cap

now there is a script in which when its size becomes exactly 1.6Gb then it clears itself and prepares files in below format in same directory-

word.cap.COB2T_1389889231
word.cap.COB2T_1389958275
word.cap.COB2T_1390035286
word.cap.COB2T_1390132825
word.cap.COB2T_1390213719

Now i want to pick all these files in a script one by one and want to perform some actions. my script is-

today=`date +%d_%m_%y`
grep -E '^IPaddress|^Node' /var/rawcap/word.cap.COB2T* | awk '{print $3}' >> snmp$today.txt

sort -u snmp$today.txt > snmp_final_$today.txt

so, what should i write to pick all file names of above mentioned format one by one as i will place this script in crontab,but i don't want to read main word.cap file as that is being edited.

Upvotes: 0

Views: 70

Answers (1)

devnull
devnull

Reputation: 123518

As per your comment:

Thanks, this is working but i have a small issue in this. There are some files which are bzipped i.e. word.cap.COB2T_1390213719.bz2, so i dont want these files in list, so what should be done?

You could add a condition inside the loop:

for file in word.cap.COB2T*; do
  if [[ "$file" != *.bz2 ]]; then
    # Do something here
    echo ${file};
  fi
done

Upvotes: 1

Related Questions