Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I run a script which generated about 10k files in a directory. I just discovered that there is a bug in the script which causes some filenames to have a carriage return (presumably a '\n' character).

I want to run a sed command to remove the carriage return from the filenames.

Anyone knows which params to pass to sed to clean up the filenames in the manner described?

I am running on Linux (Ubuntu)

UPDATE

The character causing the filename to 'break up' accross multiple lines appear to be a CR (carriage return) instead of '\n'. The filename is being diaplayed in thetitle of a text editor with %0D in the positions of where the file name breaks up. So I need to remove the CR chars from my filenames.

share|improve this question

1 Answer 1

Try with rename:

find /path/to/dir -exec rename -n 's/\n/_/' {} \+

Remove -n to actually rename the files.

share|improve this answer
    
I cd to the directory and run the command with '.' as the directory. Noting was printed to the console. Are you sure about the regex?. If so, could be that the chars are not '\n' bu rather CR or LF chars - not sure how I'd handle them if that turns out to be the case .. –  Takashi Dec 11 '10 at 16:40
    
Actually, I'm quite sure its a CR (not a '\n' character). The filename is being diaplayed in thetitle of a text editor with %0D in the positions of where the file name breaks up. –  Takashi Dec 11 '10 at 16:49
    
So use \r instead of \n. –  cYrus Dec 11 '10 at 16:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.