LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 10-24-2013, 07:06 AM   #1
Oranoran
LQ Newbie
 
Registered: Oct 2013
Posts: 6

Rep: Reputation: Disabled
find similar lines according to delimited column's value


Hi all,

kinda new here and totaly newbe in linux commands.

I have text file in which each line data is seperate by ';' delimiter.

I like to find how many rows in the file, contain some specific column's value (i.e. $6 = 1234)

Thank you all in advance.
 
Old 10-24-2013, 07:13 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,104

Rep: Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267
you can use awk. Delimiter can be given as -F\; You will need to count lines containing that given string:
$6 == 1234 {a++} and finally you will need to print the result: END { print a }
are you familiar with awk?
 
Old 10-24-2013, 07:34 AM   #3
Oranoran
LQ Newbie
 
Registered: Oct 2013
Posts: 6

Original Poster
Rep: Reputation: Disabled
Hi pan64,

Thanks for your quick response.

Unfortunately, I'm not familiar with awk.

Any chance you can give me a little hint?

Thanks again.
 
Old 10-24-2013, 07:37 AM   #4
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,104

Rep: Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267
I gave you hints, a lot. You just need to copy those lines into a single file:
awk -F\; '$6 == 1234 {a++} END { print a }'
 
Old 10-24-2013, 07:41 AM   #5
Oranoran
LQ Newbie
 
Registered: Oct 2013
Posts: 6

Original Poster
Rep: Reputation: Disabled
Thank a lot Pan64.

of course it works
 
Old 10-24-2013, 07:44 AM   #6
Oranoran
LQ Newbie
 
Registered: Oct 2013
Posts: 6

Original Poster
Rep: Reputation: Disabled
One more thing, if I may,

what should I do in order to count distinct rows?

I mean, all rows which share the same value for coulmn 6 (i.e S6==1234) will be counted as 1 row.

Thanks again.
 
Old 10-24-2013, 07:44 AM   #7
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,104

Rep: Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267
glad to help you
Happy with solution ... mark as [SOLVED]
If you really want to say thanks just click on Yes
 
1 members found this post helpful.
Old 10-24-2013, 07:51 AM   #8
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,104

Rep: Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267
$6 == 1234 {a[$0]++}
END { print length(a) }
 
1 members found this post helpful.
Old 10-24-2013, 08:17 AM   #9
Oranoran
LQ Newbie
 
Registered: Oct 2013
Posts: 6

Original Poster
Rep: Reputation: Disabled
I'm apologize, I didn't explain what I want correctly,
I want to count distinct row in the file.

distinct rows are rows which has difderent value for column 6 ($S6).

Sorry for the nag.

Thanks again for you kind help and patient.

oran
 
Old 10-24-2013, 08:20 AM   #10
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,104

Rep: Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267
awk -F\; '{a[$6]++} END { print length(a) }'
will do that. Also you can play with the array a to print the values found.
 
Old 10-24-2013, 08:28 AM   #11
Oranoran
LQ Newbie
 
Registered: Oct 2013
Posts: 6

Original Poster
Rep: Reputation: Disabled
Thanks a lot man.

Appreciate your help.
 
  


Reply


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
[SOLVED] Inserting in at a specific column (not delimited) mp85 Linux - Newbie 9 02-22-2013 05:47 PM
Bash script to find and remove similar lines from multiple files linuxquestion1 Programming 9 07-13-2011 02:45 AM
Help needed - How to check quality of a specific column in a tab-delimited file? Jason7449 Linux - Newbie 3 03-08-2010 10:36 AM
column re-alignment - space delimited to comma delimited hattori.hanzo Linux - Newbie 9 03-05-2009 01:54 AM
Concatenate column 1 and column 2 of related lines cgcamal Programming 4 11-20-2008 11:43 AM


All times are GMT -5. The time now is 01:57 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration