[Leaplist] command line question ....
Andrew
aander07 at packetmaster.com
Sat Feb 14 18:31:38 EST 2009
On Feb 14, 2009, at 5:50 PM, William A. Mahaffey III wrote:
> .... is there a way intrinsic to tcsh, bash, or perhaps using awk,
> to 'mask' off the 1st n (or last n for that matter) elements of a
> long pathname (i.e. go from '/some/darn/long/idiot/moron/path' to
> either '/some/darn/long' or /long/idiot/moron/path', for example) ?
> I have RTFM a fair amount & it is eluding me .... TIA ....
Something like this may be what you're after:
#!/bin/bash
INPUT=/some/very/long/path/name/with/a/file
# strip off the first 4 path elements of INPUT
STRIP=4
OUTPUT=${INPUT}
for idx in `seq 0 ${STRIP}`
do
OUTPUT=${OUTPUT:`expr index ${OUTPUT} '/'`}
done
echo /${OUTPUT} # /name/with/a/file
Of course, don't forget about the 'dirname' command as well. A few
loops over a path with dirname may also fit your needs.
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
More information about the Leaplist
mailing list