Replacing extension of files

hi,

i am having a certain files in a folder where i need to replace the extension with similar file name

for eg

1.csv
2.csv
3.csv
4.csv

i need to replace the extension

1.csv
1.txt
2.csv
2.txt
3.csv
3.txt
4.csv
4.txt

the text file will be 0 byte file but csv file will have data in each files

for i in *.csv
do
touch $i
done

Use cp instead of touch with parameter substitution:

for i in *.csv
do
        cp "$i" "${i/\.csv/\.txt}"
done
1 Like

I think it must be simply . not \.
To produce 0 length files:

for i in *.csv
do
  touch "${i/.csv/.txt}"
done

Or

for i in *.csv
do
  touch "${i%.*}.txt"
done

Old Unix shells need an external program basename

for i in *.csv
do
  touch `basename "$i" .csv`.txt
done
1 Like

basename internally is "${path##*/}" for bash and ksh.