0

I have many files in unix system that match the pattern 'ZLOG_106475_20170517.zip' where, 106475 denotes the id within the filename.

I want to fetch the names of all such files having id greater than a specific no e.g. 106171

And push the names into a .lst list file in unix.

Can someone help me?

nitinr708
  • 1,393
  • 2
  • 19
  • 29
sailesh
  • 93
  • 1
  • 1
  • 5

1 Answers1

3

In bash with a for construct

for file in ZLOG_*.zip; do
    [[ -e $file ]] || continue    # check file exist
    id=${file#ZLOG_}   # remove prefix
    id=${id%%_*}       # remove suffix
    if ((id>106171)); then
        echo "$file"
    fi
done >list.txt
Nahuel Fouilleul
  • 18,726
  • 2
  • 31
  • 36