2

I have folder named 'data' in the terminal folder. Some of the file names in data have a ',' in them. I am able to list them by

$ cd data $ ls -i |grep -E '\,' 

But I don't know how to remove ',' from those filenames. From my research I tried something like grep -E '\,' | sed ',' but it did not work. If I can't remove the commas from the file filenames, I am willing to delete those files but I can't delete them either (it says no such file or directory) on terminal folder or with the command line using rm.

1 Answer 1

6

Using the bash shell, you could loop over all of the filenames that have a comma in them and rename them to remove all the commas:

for f in *,*; do mv -- "$f" "${f//,/}"; done 

With a sample run:

$ touch foo,bar a,b,c,d $ ls a,b,c,d foo,bar 

The results are:

$ for f in *,*; do mv -- "$f" "${f//,/}"; done $ ls abcd foobar 

This will clobber any destination filenames that already exist.

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.