Hello all, first post.
Due to various reasons, I'm stuck writing some fairly complex scripts in shell (ksh or bash, depending on the system). I have quite a bit of perl experience, but little experience using shell for more than really simple tasks.
If there is some excellent resource that I don't know about that maps common perl procedures to an equavelent shell procedure I'll happily go figure it out on my own. Since I haven't found such a thing, I'll just throw them out here.
Things I'm trying to do in shell, that would be easy in perl that I can't seem to figure out in shell:
1) Take a space deliminated value from awk and assign it to 2 variables.
In perl, I would do something like this:
Code:
$sys_return=`tar -tvf /dev/nst0 | awk '{print $3,$6}'`;
($fileName,$fileSize) = split (/\s/,$sys_return);
In bash, I get stuck doing something like this:
Code:
FNAME=`tar -tvf /dev/nst0 | awk '{print $6}'`
mt -f /dev/nst0 bsfm 1
FSIZE=`tar -tvf /dev/nst0 | awk '{print $3}'`
echo "restoring $FNAME with filesize of $FSIZE"
It must be easier, right?
2) Read a file and look for a value line by line
Perl:
Code:
open(FILE,"list.txt");
foreach $line (<FILE>) {
$verified = 1 if ($line =~ /$pattern_to_match/);
}
shell:
I'm not even sure, at the moment. I was searching for that when I signed up here.
I see some references to this:
Code:
while read line
do
if [[ $line == *$pattern_to_match* ]]
then
#do something
fi
done
but none of the sample code I can find actually shows how to pick which file you want to read from.
Thanks for assistance in advance, I'm sure I'll have more questions later!