2

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.

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')" '{*}'
  • @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 '14 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). – Stéphane Chazelas Jun 2 '14 at 7:46
  • @StéphaneChazelas sorry - I'm not sure to whom you are speaking, and what suggestions you have to improve the code? – Felipe Alvarez Jun 3 '14 at 6:18
  • @FelipeAlvarez, the discussion was with rici and about my edit and the need for quotes around $(...). – Stéphane Chazelas Jun 3 '14 at 6:37
  • I've accepted this answer because it immediately satisfies the problem. A pity that csplit won't obey backslash r \r – Felipe Alvarez Jun 4 '14 at 7:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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