I doing the follwing script , but found problem to store it to a shell variable.
#! /bin/sh
for temp in `find ./dat/vector/ -name '*.file'`
do
echo $temp
nawk -v temp=$temp 'BEGIN{ split(temp, a,"\/"); print a[4]}'
done
output:
./dat/vector/drf_all_002.file
drf_all_002.file
......
......
It shows me all the file ending with .file under ./dat/vector directory.
But I want to store the value of ( in this case ) a[4] to a shell variable fname and also the base name of the file ie, drf in this case to a separate shell variable called basename..
If any other idea with sed or with any other command most welcome..
Objective is to find all the file with extension .file and then store only the file name to a shell variable
and the base name of the file to another shell variable.
#! /bin/sh
for temp in `find ./dat/vector/ -name '*.file'`
do
echo $temp
fname = `nawk -v temp=$temp 'BEGIN{ split(temp, a,"\/"); print a[4]}' `
done
fpmurphy is refering to a useful commandline tool called 'basename'
It returns everything after the last / character.
So if you call:
basename /thing/blah/stuff/filename
you get:
filename
You can use this to get just the filename out of your data