printing rows with repeated strings
Hi guys,
I am trying to print the rows with repeated strings (in this example it is the word DOG with some numbers) in a file. so for example: col1 col2 col3 DOG1 233 1 DOG1 231 1 DOG4 230 5 I can do something like Code:
awk '{if($3>=1){print}}' | sort -k1,1 |
Could you explain your goal in more detail? For example:
Do you need to print out lines that match a specific string, or any repeating string in the file? Are the matching lines sequential, or can they be scattered through the file? Are the matched words all in the same column, or can they be in different ones? Does the order of the output matter, and if so, how should it appear? You might want to give use a larger example of the input, and perhaps tell us the context of what you're trying to do. |
Hi,
I need it to print out lines that match a repeating string and they are scattered throughout the file. The matched words are also in the same column and the order of the output does not matter as long as all of the lines with the repeated strings are printed in the output file. So in the example below, the word "DOG1" should appear in the output file 4 times with the corresponding information from the rest of the columns. The word "DOG3" should appear twice in the output file with the corresponding information from the rest of the columns (for example, it should look like this: DOG3 0.04 2) col1 col2 col3 DOG1 233 1 DOG1 231 1 DOG4 230 5 DOG1 0.5 3 DOG3 0.04 2 DOG0 4 23 DOG1 5 0.1 DOG3 63 5 |
Hi, verse123. Here's how I read your program specification.
Quote:
Code:
$ cat dogs.txt Code:
$ cat dog-finder.awk Code:
$ ./dog-finder.awk dogs.txt |
A Perl version:
Code:
perl -ane 'push @{$s{$F[0]}},$_;END{for(keys %s){print @{$s{$_}} if @{$s{$_}}>1;}}' file.txt Code:
perl -ane '$s{$F[0]}.=$_;END{print for(grep {/\n./}values %s)}' file.txt Code:
perl -ane '$s{$F[0]}.=$_;END{print grep{/\n./}%s}' file.txt |
All times are GMT -5. The time now is 01:11 AM. |