Renaming a filename

Hi friends ,

i want to change the filename as below

 
filename=ABC_HYND_JDHD_20130125120345.txt
expected output : ABC_HYND_JDHD_20130125.txt

i have tried using awk but not able to procedd futher. i am trying to do the above in single commad.

 
echo "ABC_HYND_JDHD_20130125120345.txt" | awk -F"." '{ x=$1;y=$2}'

plz help

 
$ echo $filename | nawk -v OFS=_ -F_ '$NF=substr($NF,1,8)".txt"'
ABC_HYND_JDHD_20130125.txt
1 Like
echo "ABC_HYND_JDHD_20130125120345.txt" | sed 's/[0-9]\{6\}\.txt/.txt/'

or

echo ${filename/[0-9][0-9][0-9][0-9][0-9][0-9].txt/.txt}
1 Like

@itkamaraj , @ bala.. Thank you so much . It works as expected. :slight_smile: