LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to compare input lines but ignore decimals (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-compare-input-lines-but-ignore-decimals-4175466010/)

lili2002 06-14-2013 09:06 AM

How to compare input lines but ignore decimals
 
If I have below lines in a file and I want to sort first and count unique ones but ignore decimals when comparing, what should i do in uniq options?

Error in test. start=5, executing=12, end=60
Error in test. start=1, executing=20, end=80
Error in test. start=10, executing=5, end=100
Warn in test. begin=1, end=2
Warn in test. begin=4, end=9

I want the output will be like:

3 Error in test. start=5, executing=12, end=60
2 Warn in test. begin=1, end=2

thedaver 06-14-2013 10:32 AM

Looks like you are counting matches of string "Error in test" and "Warn in test", right?

If you assume that both phrases end with the period "." character and you only want to count the instances, then this should work.

Code:

cat sourcefile.txt | grep -E "^Error in test|^Warn in test" | sort | uniq -c

allend 06-14-2013 10:35 AM

If you are only interested in the number of unique messages then
Code:

cat junk2.txt | cut -f1 -d '.' | uniq -c
where junk2.txt contains the input data you posted produces
Quote:

3 Error in test
2 Warn in test


All times are GMT -5. The time now is 06:44 AM.