Hello,
I have this path and file:
/dir/dir/dir/dir/dir/dir/dir/dir/dir/THIS_SPOT/fle.txt
I want to end up with:
/dir/dir/dir/dir/dir/dir/dir/dir/dir/THIS_SPOT/fle.txt[tab]THIS_SPOT
Take the dir after the 10th slash, add a tab at the end and paste the dir it copied.
Thanks
Scott
2
echo "/dir/dir/dir/dir/dir/dir/dir/dir/dir/THIS_SPOT/fle.txt" | awk -F/ '{print $0 "\t" $11}'
Try using basename and dirname.
This is kind of brute-force, but it seems to work. Note I'm using commas instead of slashes in the s command.
DIR="/dir/dir/dir/dir/dir/dir/dir/dir/dir"
echo ..... | sed "s,$DIR/\(THIS_SPOT\)/file.txt,&\t\1,"
This might be what you are actually looking for:
echo ..... | sed "s,/\([^/]*/\)\{9\}\([^/]*\).*,&\t\2,"
@scottn: maybe more precisely to print field NF-1:
awk -F/ '{print $0 "\t" $(NF-1)}'
Another one with sed:
sed 's_.*/\([^/]*\)/.*_&\t\1_'