Hello,
I am trying to work with filename in Unix.
So in my example a have a filename like : ABC_totoalerte.txt and I want just to capture totoalerte.txt.
How can i do it , i check it with cut -c,4-* but it didn't work.
Can you help me about this problem. Thanks..
vino
2
This solution is very specific to the format you gave i.e. ABC_anyfilename.extension
echo ABC_totoalerte.txt | awk -F"_" '{ printf $2 }'
Vino
Try This
But this is also for a specific structure :-
sed 's/^[a-z]*\_\([a-z]*[0-9]*[.][a-z]*\)/\1/' file.txt
ssk
4

echo ABC_totoalerte.txt | cut -d"_" -f2
should work.
Use a good shell (ksh, bash) and then use the shell's built-in features to do this lightning-fast...
$ FILENAME="ABC_totoalerte.txt"
$ FILENAME=${FILENAME##*_}
$ echo $FILENAME
totoalerte.txt
Cheers
ZB
Lestat
6
If you always want to get the last part after '_' do this
ls -1 | cut -d "_" -f2