Tag Info

New answers tagged

1

As long as you're interested in the last column, you can do it with sort and uniq: $ sort -k3n test.txt | uniq -f2 -D 1+1 = 2 2x1 = 2 BLABLABLA = 2 Here, the sort option -k3n causes the file to be sorted starting with the third field, in numeric order; the options to uniq are: -f2 Skip the first two fields before checking for uniqueness -D Print ...


0

Use Uniq. uniq -f 3 <file name>


0

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 search_term="$1"; shift local wait_time="${1:-5m}"; shift # 5 minutes as ...


6

The GNU grep can do it grep -z 'is\san\sexample\sfile.' file To fulfill some points which arise in comments there are some modifications to script: grep -oz '^[^\n]*\bis\s*an\s*example\s*file\.[^\n]*' file Regarding huge files I have no imagination of memory limitation but in the case of problem you are free to use sed sed '/\bis\b/{ :1 ...


6

Try this: pcregrep -M '\bThis\s+is\b' <<EOT This is an example file. EOT


1

To show matching lines, count them, and show the count, with awk: awk '/ERROR/{err++; print} END{print "errors:", err}' To summarize errors and exceptions: awk '/ERROR/||/Exception/{faults++; print} END{print "faults:", faults}' To count errors and exceptions separately: awk '/ERROR/{err++; print} /Exception/{exc++; print} END{print "errors:", ...


0

Just use wc command with the -l option: wc -l If you wish to print the logs as well, then you can use tee: cat logs.txt | grep -i error | tee >(wc -l)


1

I take it that "rolls up" means that all newlines are removed and the output of each command is thus "rolled up" to a single line. If so, your grep ... | awk ... will work, but you don't need both commands ("never use two when one will suffice" is generally a good idea). In addition, your command line has a couple issues (like no input for grep but a ...


2

For filtering data from file is better to use grep. For example: grep <search string> <filename> With awk you can use something like: awk '/string/ {command}' <filename> To get IPs counted you can use uniq -c <filename> This will provide you uniq IPs with count


0

printf %s\\n 'Apr 30 aaa' \ 'May 1 bbb' \ 'Feb 29 ccc' \ 'Feb 30 ddd' | sed -n '/^\(Apr\|Jun\|Sep\|Nov\) \([1-9]\|[12][0-9]\|30\)\>/p /^\(Jan\|Mar\|Jul\|Aug\|May\|Oct\|Dec\) \([1-9]\|[12][0-9]\|3[01]\)\>/p /^\(Feb\) \([1-9]\|[12][0-9]\)\>/p' Output: Apr 30 aaa May 1 bbb Feb 29 ccc


5

To extract lines that start with May 1: grep "^May 1\b" file Or: sed -n '/^May 1\>/p' file Or: awk '/^May 1\>/' file The above two assume a tool, such as the GNU awk or sed, that supports \> as a word boundary regex. The purpose of the word boundary is to prevent the regex from matching, for example, May 10. More If you are looking for ...


1

You can use awk to search by the third column awk -F"-" '$3 ~ /@woods.com/' list.txt


0

Solved after fully updating to Freya stable following this method. It involves: removing daily sources, adding stable sources, replacing kernel 3.13 with 3.16.


1

Here’s a way to get the results you want with GNU awk: awk ' BEGINFILE { if (FILENAME ~ "^animals/" || FILENAME ~ "/animals/") { this_name = substr(FILENAME, index(FILENAME,"animals/")+length("animals/")) i = index(this_name, ".") if (i > 0) this_name = substr(this_name, 1, i-1) ...


0

I think if you give the patterns as input to grep using stdin, it will concatenate results for all patterns. So AFAIK the only way to overcome this problem is to call a new instance of grep for each pattern. This script would work in this case for animalName in $(ls -1 ~/animals | cut -d. -f1); do echo "$animalName: $(grep -R -h -c $animalName ...


0

sed -E ' s/[0-9.+-]*e[-+]?[0-9]{2}/ &/g s/ *(.{22}[0-9])/\1/g' < input.txt > output.txt That assumes GNU or FreeBSD (or derivative like OS/X) sed, or a sed conformant to the next version of the Unix/POSIX standard (for -E).


9

GNU grep's -w will only consider the 26+26+10+1 (ASCII letters, digits and underscore) as word constituents. You can't change that, even by using a different locale (even in a locale where é is considered a letter, Stéphane would still be St and phane separated by the non-word é). You can however implement that logic by hand: grep -E ...



Top 50 recent answers are included