1

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.

1 Answer 1

2

Try with rename:

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

Remove -n to actually rename the files.

3
  • 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, 2010 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, 2010 at 16:49
  • So use \r instead of \n.
    – cYrus
    Dec 11, 2010 at 16:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .