Ander2
Ander2

Reputation: 5658

piped sed fails to do substitution

I've some files with non-ascii characted that I would like to remove. I'm trying to replace those characters with '-' in the filenames but It doesn't work.

This is my command

ls Argi* | xargs -I file basename file '.eps' | sed "s/[^a-zA-Z0-9]/-/"

also tryed:

ls Argi* | xargs -I file basename file '.eps' | sed "s/\W/-/"

Any clue why is not it working?

Upvotes: 0

Views: 146

Answers (2)

Dennis Williamson
Dennis Williamson

Reputation: 360105

Use the prename command you likely have on your system. It may be called rename, but there's another program by that name that works differently.

prename 's/[^a-zA-Z0-9]/-/' Argi*

Upvotes: 0

Kent
Kent

Reputation: 195059

what do you want for

replace those characters with '-' in the filenames

I guess you just want to get an output without those characters instead of renaming the original file. because your sed command doesn't do the rename at all.

then you could try iconv:

kent$  l
-rw-r--r-- 1 kent kent  0 2012-07-03 12:20 Argiö.eps
-rw-r--r-- 1 kent kent  0 2012-07-03 12:20 Argiü.eps


kent$  ls Argi*|iconv -f utf8 -t ascii//TRANSLIT 
Argio.eps
Argiu.eps

this would not replace those letters with "-", but with ASCII.

Upvotes: 3

Related Questions