Logo Background

Unix Filename Pattern Matching

  • By on November 23, 2010 | No Comments

    Looking on how to write Unix shell script for filename pattern matching? There’s several way you can write it using regular expression technique in scripting.

    Let’s say you have a scenario where you want to perform certain command execution e.g file processing if certain filename exist in certain folder.

    Here’s the example of a simple Unix shell script you can use to accommodate your file processing scenario.

    #!/bin/bash
     
    V_SOURCE_PATH=/export/home/oracle
     
    cd $V_SOURCE_PATH
     
    for file in ./*_new.txt ; do
     
            if [ -e "$file" ] # Make sure file exists and isn't an empty match
            then
            echo "Filename with pattern _new.txt exist"
            else
            echo "Filename with pattern _new.txt not exist"
            fi
     
    done
    Previous
    Next
    » How To Remove W3 Total Cache Comment Footer
Leave a Comment