unix - Bash Script to run against all .log files -
i have bash script called (log2csv). while in current directory can type in terminal:
log2csv *.log
this run script on every .log file in current directory.
alternatively can run against single .log file with
log2csv test1.log
instead of typing log2csv *.log, can have *.log included in script? can type log2csv in directory , runs. know can alias that, rather have script it.
here bash script running:
#!/bin/bash  path        base=$(basename "$path")       noext="${base/.log}"       [ -e "${noext}.csv" ] && continue       /users/joshuacarter/bin/read_scalepack.pl "$path" > "${noext}.csv"  done 
change:
for path to:
for path in *.log or, perhaps better:
names=( "$@" ) if [ "${#names}" = 0 ] names=( *.log ) fi path in "${names[@]}" and can consider whether set options such shopt -s nullglob well.  uses shell arrays handle names blanks etc in them.  uses command line arguments if given, , list of files *.log being expanded if there no command line arguments.
Comments
Post a Comment