# Removing characters of a list of filenames.



## Graaf_van_Vlaanderen (Dec 26, 2009)

Can anybody point me to a script that removes a certain character from a list of files? Currently I'm using the C-shell.


----------



## Alt (Dec 26, 2009)

sed -i .bak 's/WORD//g' *
this must remove all WORD from all files in current dir (*)


----------



## graudeejs (Dec 26, 2009)

in sh alike shells, some examples:

```
for i in list of files; do mv -f  $i $(echo $i | tr " \(\)\[\]\{\}/_/g" "_"); done
```

or

```
for i in `ls /path/to/files/`; do mv -f $i $(echo $i | tr " \(\)\[\]\{\}/_/g" "_"); done
```


```
for i in `ls /path/to/files/`; do mv -f $i $(echo $i | sed 's/Ä/_/g') | sed 's/Å¡/_/g' | sed '/Ä“/_/g'; done
```
Last one I haven't tested... it uses utf-8 2 byte characters... but i think it should work

here's my rmwinshit.sh


----------



## Graaf_van_Vlaanderen (Dec 26, 2009)

Based on your feedback I tried something different:


```
for i in `ls`;
do newname=`echo $i | sed 's/string_to_replace/new_string/g'`;
mv $i $newname;
done
```

This seems to work too, considering we're in the right directory with only files.


----------



## graudeejs (Dec 26, 2009)

check tr(1)....

and... ah I'll fix IMPORTANT but in my scripts above in 2 min


----------



## graudeejs (Dec 26, 2009)

Fixed bugs....
sed really wan't good choice... tr is much better for you.... also sed wouldn't work the way I wrote at first.... {I was thinking of using it as tr.... )

please check my 1st post again


----------



## Alt (Dec 26, 2009)

> removes a certain character from a list of files?





> removes a certain character from filenames?


Feel difference ?


----------



## Graaf_van_Vlaanderen (Dec 26, 2009)

Alt said:
			
		

> Feel difference ?



I agree my post was somewhat confusing.
It should have been: "removes a certain character of the file names of a bunch of files."


----------



## J65nko (Dec 26, 2009)

For a similar discusion see http://www.daemonforums.org/showthread.php?t=2565


----------



## Graaf_van_Vlaanderen (Dec 27, 2009)

J65nko said:
			
		

> For a similar discusion see http://www.daemonforums.org/showthread.php?t=2565



Not bad, though I noticed a few errors in the explanation. 
The "s" doesn't stand for "search", but for "substitute".
The search behavior of the stream editor is inherent to the program.


----------



## Graaf_van_Vlaanderen (Jan 4, 2010)

Here is another one I found that works pretty well. It replaces empty space in a file mane with a character. In this example empty space in the file name is replaced by "-":


```
find . -name "* *"| while read file
do
  rename "$file" "`echo "$file"| nawk ' BEGIN {OFS="-"} $1=$1 '`"
done
```


----------

