#!/bin/ksh
typeset chCmd="/path/to/Generateadd.sh -ip"
typeset pDir=/path/to/your/directory
typeset pFile=""
typeset chIP=""
ls $pDir | while read pFile ; do
chIP="${pFile%.csv}" # chop off the extension
chIP="${chIP#card_}" # chop off the leading "card_"
$chCmd $chIP
done
exit 0
It is a bad idea to have relative paths in scripts, so i changed ./Generateadd.sh to a call with the absolute path. If you use relative paths in scripts that means the script will work in one directory but not in another.
I dont think this script will work if the file name is "card_xyz_something_something_10.87.162.211.csv"
So, what I would like is the "_" just before the IP address to be considered for chopping off anything prior to that so I am just left with the IP address.
Can you please help tweak it and get it working for me ?
You know what? Me neither. But it would have been a nice thing to define your problem correctly instead of letting me guess. I am a Sysadmin, being a psychic is not part of the job description.
Yes, i can. Replace:
chIP="${chIP#card_}" # chop off the leading "card_"
with this:
chIP="${chIP##card_*_}" # chop off the leading "card_" and everything up to the last "_"