New answers tagged

0

This is mostly stolen from here: fortune | sed ':a;N;$!ba;s/\n[[:space:]]\{2\}--/ --/' From the original answer: Explanation: Create a label via :a. Append the current and next line to the pattern space via N. If we are before the last line, branch to the created label $!ba ($! means not to do it on the last line as there should be one ...


0

Removal of ^M without special signs: $ tr -d '\015' <file1 >file2 $ mv file2 file1


1

To give yet another option, you can just hit Enter (i.e., a literal newline): $ echo "the rain in spain > falls mainly on the plain" > foo Note that you don't type the > at the beginning of the second line.  That's the secondary shell prompt, $PS2, which the shell prints when you type an incomplete command (e.g., in this case, a command with an ...


0

POSIX 7 says you can't http://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html -e is not defined and backslashes are implementation defined: If the first operand is -n, or if any of the operands contain a <backslash> character, the results are implementation-defined. unless you have an optional XSI extension. So use printf instead: ...


5

This can be done by using the $'\n' syntax (see http://stackoverflow.com/a/3182519/3822464). So for example: fgrep word1$'\n'word2 Or you can wrap the whole PATTERN that way (credit don_crissti) fgrep $'word1\nword2\nword3'


5

grep -F 'word1 word2' infile or, if you prefer on one line: grep -F -e 'word1' -e 'word2' infile



Top 50 recent answers are included