Tag Info

New answers tagged

0

Please not that for GNU utilities (and in general), casing of the command line options used matter. Try grep -C1 string1 file.txt instead. Note the capital 'C'! BTW, the '-c' flag means count. Instead of showing all individual occurrences it just shows the total number of lines the string occurs on in your file(s).


0

Let me expand on @00prometheus answer (which is the best one). Maybe you should use a timeout instead of waiting indefinitely. The bash function below will block until the given search term appears or a given timeout is reached. The exit status will be 0 if the string is found within the timeout. wait_str() { local file="$1"; shift local ...


0

Try using single quotes ' instead, like this: grep -Po '(?s)(<h2>.+?<!-- /endcontent -->)' input.html > output.html Grep acts differently when things are double-quoted.


2

Add option -z to your GNU grep command: cat testfile | grep --color=always -z 'hello' or shorter grep --color=always -z 'hello' testfile


1

This is an old question, but to anyone else wondering the simplest way to do this there is a win utility called "strings" which does exactly what you're after. https://technet.microsoft.com/en-gb/sysinternals/bb897439.aspx Basically, it pulls all the unicode out of files so you can then pipe it to whatever windows grepalike you use be it findstr (native) ...


2

echo aaaa bbbb ccc bbbb azesd bbbb | tr " " " " | sort | uniq -c | sort -n | tail -n1 outputs 3 bbbb


3

Add grep's option --line-buffered and sed's option --unbuffered.


1

Use grep's --line-buffered option. By default, utilities use line-buffering if their standard output is a terminal, but use bigger buffers (probably 4 or 8 kB) when their output is connected to a file descriptor or a pipe. You're lucky that tail -F uses line-buffering by default, and grep has a command line option to enable that. I'm not aware of a generic ...


0

Cyrus already got you the perfect answer, but if you wana do it with grep ( which is more complicated) you grep the lines you do not want and you put them in a file: grep 'd' -A 1 testing_grep.txt > otherfile.txt otherfile.txt content will be : dddddddddddddddddd llllllllllllllllll dddddddddddddddddd llllllllllllllllll Then you use the diff command ...


1

Try this with GNU sed: In pattern space (current line) search (//) a line containg d. Only for those lines append the next line of input into the pattern space (N) and delete pattern space (d). sed '/d/{N;d;}' testing_grep.txt Output: aaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbb bbbbbbbbbbbbbbbbbb cccccccccccccccccc fffffffffffffffff fffffffffffffffff



Top 50 recent answers are included