[plug] A bit of gross bash code
Anthony J. Breeds-Taurima
tony at cantech.net.au
Wed Mar 7 16:39:08 WST 2001
On Wed, 7 Mar 2001, Brad Campbell wrote:
> Ok, I'm sure you have had enough of me today, but here is a bit
> of bash code I wrote to solve a problem..
> Question is, is there an easier way to do this.. or am I on the right
> track. I mean, it works, but it's very rough.
> As you can see, I'm pretty new to the bash scripting arena, but I can
> read man pages :p)
Try this:
cd /dev
for i in * ; do
TYPE=$(ls -la "$i"|cut -c1)
IDS=$(ls -lan "$i"|awk 'BEGIN {OFS=":"} {print $3,$4,$5,$6}'|sed -e 's/,//g')
if [ "$TYPE" = "b" -o "$TYPE" = "c" -o "$TYPE" = "u" ] ; then
echo "${TYPE}:$IDS:$i"
fi
done
It does use awk, which yours doesn't sorry if it's not there.
You should be able to combine this with gregs code if awk isn't available.
IDS=$(ls -lan "$i" | sed -e 's/[ ,]\+/ /g' | cut -f 3,4,5,6 -d " "|sed -e 's/,//g')
I don't think this will die on files with spaces and/or colonms BUT it is much
longer.
Yours Tony.
/*
* "The significant problems we face cannot be solved at the
* same level of thinking we were at when we created them."
* --Albert Einstein
*/
More information about the plug
mailing list