Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 06-14-2013, 09:06 AM   #1
LQ Newbie
Registered: Jul 2012
Posts: 7

Rep: Reputation: Disabled
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
Old 06-14-2013, 10:32 AM   #2
Registered: Jan 2010
Posts: 65

Rep: Reputation: 21
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.

cat sourcefile.txt | grep -E "^Error in test|^Warn in test" | sort | uniq -c
Old 06-14-2013, 10:35 AM   #3
Senior Member
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 4,574

Rep: Reputation: 1491Reputation: 1491Reputation: 1491Reputation: 1491Reputation: 1491Reputation: 1491Reputation: 1491Reputation: 1491Reputation: 1491Reputation: 1491
If you are only interested in the number of unique messages then
cat junk2.txt | cut -f1 -d '.' | uniq -c
where junk2.txt contains the input data you posted produces
3 Error in test
2 Warn in test

Last edited by allend; 06-14-2013 at 10:38 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
sed match and ignore new lines ted_chou12 Programming 5 02-26-2012 11:33 AM
[SOLVED] Beginng C programming - how to input decimals from keyboard and calcuate as floats? keithostertag Programming 4 02-17-2012 11:11 AM
[SOLVED] How can I ignore lines with partial similarity and retain only one. btacuso Linux - Newbie 3 03-13-2010 02:34 PM
How would I ignore other lines in a file with non unique words? btacuso Linux - Newbie 1 05-24-2009 08:20 AM
how to compare decimals linuxboy69 Linux - Software 2 08-16-2004 02:43 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:03 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration