3

I have a file with \r\n line endings (CRLF carriage return line feed).

This command works:

$ csplit --silent --prefix=email-emailbad.txt- \
    --digits=3 emailbad.txt '/^\.^M/'+1 '{*}'

This requires that I press CTLR+V and then CTRL+M to insert an actual carriage return character.

I want this to work, so that I'm using only printable characters (for SVN, etc.)

$ csplit --silent --prefix=email-emailbad.txt- \
    --digits=3  emailbad.txt '/^\.\r/'+1 '{*}'

I've tried with single and double quotes, and without quotes. Any suggestions welcome.

1 Answer 1

3

If you are using, ksh93, zsh or bash, you can use the $'...' ksh-extension, which does C-style backslash escape interpretation inside the quoted string:

csplit --silent --prefix=email-emailbad.txt- --digits=3 \
       emailbad.txt $'/^\.\r/+1' '{*}'

Otherwise, you can use printf to create the string, in a very similar way:

csplit --silent --prefix=email-emailbad.txt- --digits=3 \
       emailbad.txt "$(printf '/^\.\r/+1')" '{*}'
6
  • @stephaneChazelas: Thanks. The quotes around the printf are not required, by the way, although they're probably a good idea. (The default value for IFS is <space><tab><newline>. I think that's standard; it certainly works in both bash and zsh)
    – rici
    Jun 2, 2014 at 6:36
  • 1
    Why would you invoke the split+glob operator here? To save a couple of keystrokes, and cause that code not to be portable to contexts where $IFS is not the default? (as a note zsh's $IFS also includes the NUL character). Jun 2, 2014 at 7:46
  • @StéphaneChazelas sorry - I'm not sure to whom you are speaking, and what suggestions you have to improve the code? Jun 3, 2014 at 6:18
  • @FelipeAlvarez, the discussion was with rici and about my edit and the need for quotes around $(...). Jun 3, 2014 at 6:37
  • I've accepted this answer because it immediately satisfies the problem. A pity that csplit won't obey backslash r \r Jun 4, 2014 at 7:19

You must log in to answer this question.

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