Hi,
I need a script which do below
I have a filename: TEST2013_09_17_XX_XX_XX.csv
Now script should create a new file with name: XX_XX_XX.csv
Or I should say i need the output as XX_XX_XX.csv
Please help. Mant thanks in advance
Hi,
I need a script which do below
I have a filename: TEST2013_09_17_XX_XX_XX.csv
Now script should create a new file with name: XX_XX_XX.csv
Or I should say i need the output as XX_XX_XX.csv
Please help. Mant thanks in advance
Hi,
Here examples of cut command:
$ echo 'TEST2013_09_17_XX_XX_XX.csv' | cut -d'_' -f4-
XX_XX_XX.csv
$ echo 'TEST2013_09_17_XX_XX_XX.csv' | cut -d'_' -f1-
TEST2013_09_17_XX_XX_XX.csv
$ echo 'TEST2013_09_17_XX_XX_XX.csv' | cut -d'_' -f2-
09_17_XX_XX_XX.csv
$ echo 'TEST2013_09_17_XX_XX_XX.csv' | cut -d'_' -f3-
17_XX_XX_XX.csv
$ echo 'TEST2013_09_17_XX_XX_XX.csv' | cut -d'_' -f4-
XX_XX_XX.csv
$ echo 'TEST2013_09_17_XX_XX_XX.csv' | cut -d'_' -f4-5
XX_XX
$ echo 'TEST2013_09_17_XX_XX_XX.csv' | cut -d'_' -f-5
TEST2013_09_17_XX_XX
Regards.
Not sure exactly what you are after but here goes longhand:-
Last login: Wed Sep 18 11:46:02 on ttys000
AMIGA:barrywalker~> file_and_path="~/TEST2013_09_17_XX_XX_XX.csv"
AMIGA:barrywalker~> new_file_and_path="/tmp/"${file_and_path:17:12}
AMIGA:barrywalker~> echo "$new_file_and_path"
/tmp/XX_XX_XX.csv
AMIGA:barrywalker~> _
Another one...
file=TEST2013_09_17_XX_XX_XX.csv
echo ${file/*[0-9]_/}
--ahamed