Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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')" '{*}'
share|improve this answer
    
@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 at 6:36
    
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 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 at 6:18
    
@FelipeAlvarez, the discussion was with rici and about my edit and the need for quotes around $(...). –  Stéphane Chazelas Jun 3 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 at 7:19

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.