LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   find similar lines according to delimited column's value (https://www.linuxquestions.org/questions/linux-newbie-8/find-similar-lines-according-to-delimited-column%27s-value-4175481982/)

Oranoran 10-24-2013 06:06 AM

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.

pan64 10-24-2013 06:13 AM

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?

Oranoran 10-24-2013 06:34 AM

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.

pan64 10-24-2013 06:37 AM

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 }'

Oranoran 10-24-2013 06:41 AM

Thank a lot Pan64.

of course it works :)

Oranoran 10-24-2013 06:44 AM

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.

pan64 10-24-2013 06:44 AM

glad to help you
Happy with solution ... mark as [SOLVED]
If you really want to say thanks just click on Yes

pan64 10-24-2013 06:51 AM

$6 == 1234 {a[$0]++}
END { print length(a) }

Oranoran 10-24-2013 07:17 AM

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

pan64 10-24-2013 07:20 AM

awk -F\; '{a[$6]++} END { print length(a) }'
will do that. Also you can play with the array a to print the values found.

Oranoran 10-24-2013 07:28 AM

Thanks a lot man.

Appreciate your help.


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