SED question

Hello
i have some file names and would like to strip off the extension .cvs or .xls AND EVERYTHING After it and then replace it with .txt.

I have tried the following but it seems not to work. Any ideas to fis it?

THANKS!

OUTPUTNAME= $(echo `INFILE[${NUMB}]` sed 's_\[\.csv._|\.xls']_.txt)

If your sed supports extended regular expressions this should do it:

sed -E 's/(\.csv|\.xls).*$/.txt/'

Otherwise:

sed -e 's/\.csv.*$/.txt/' -e 's/\.xls.*$/.txt/'

Thx I'll give it a whirl

With AWK

awk -vfile=abc.csv '{sub(/(\.csv|\.txt.).*$/,".txt",file);print file}' <<<""
1 Like

Thanks! the first one worked, im sure the others are good too