LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 06-14-2013, 09:06 AM   #1
lili2002
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
thedaver
Member
 
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.

Code:
cat sourcefile.txt | grep -E "^Error in test|^Warn in test" | sort | uniq -c
 
Old 06-14-2013, 10:35 AM   #3
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,371

Rep: Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750
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

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


Reply



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:47 AM.

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