How to strip .csv from file name


I need some help striping out ".csv" from a file in Linux.



Any help would be appreciated.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

perl -ne 'rename $_,s/\.csv//r or warn "$_ $!" for @ARGV' DDP_pub_20150724093834.csv.log
mv DDP_pub_20150724093834{.csv,}.log
xbox360dpAuthor Commented:

perl -ne 'rename $_,s/\.csv//r ... isn't working for me.

How did you use it?
Did you get a warning message?
Did the other command work for you?
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Gerwin Jansen, EE MVETopic Advisor Commented:
Just 1 file?

mv DDP_pub_20150724093834.csv.log DDP_pub_20150724093834.log
xbox360dpAuthor Commented:

Sorry I should have been more clear in my original question. I need the script to remove the .csv no matter what the file name is. So a "mv" command or any command that requires the exact filename will not work for me.

When I execute  .... perl -ne 'rename $_,s/\.csv//r ... all I get is > and the file has been changed.
the file has been changed.
Isn't that what you wanted?

any command that requires the exact filename will not work
If you did not use the exact filename as the argv to the perl command, what did you use?
Gerwin Jansen, EE MVETopic Advisor Commented:
In the folder where your .csv. file is (or files are), try this:
for a in $(ls *.csv*); do echo mv $a $(echo $a | sed 's/\.csv//') ; done;

Open in new window

It should list a set of mv commands like this:
mv DDP_pub_20150724093834.csv.log DDP_pub_20150724093834.log

Open in new window

If you see the correct mv commands, remove the first 'echo' from the line to rename the files as you would.
perl -e 'rename $_,s/\.csv//r or warn "$_ $!" for @ARGV' *.csv*
should remove .csv from all files in the current working directory
so should
for f in *.csv* ; do mv $f ${f/.csv} ; done

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Gerwin Jansen, EE MVETopic Advisor Commented:

for f in *.csv* ; do mv $f ${f/.csv} ; done

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.