Sponsored Content
Top Forums Shell Programming and Scripting count identical strings print last row and count Post 302435424 by dcfargo on Wednesday 7th of July 2010 10:02:08 AM
Old 07-07-2010
count identical strings print last row and count

I have a sorted file like:

Code:
Apple 3
Apple 5
Apple 8
Banana 2
Banana 3
Grape 31
Orange 7
Orange 13

I'd like to search $1 and if $1 is not the same as $1 in the previous row print that row and print the number of times $1 was found.

so the output would look like:

Code:
Apple 8 3
Banana 3 2
Grape 31 1
Orange 13 2

I'm very new and don't have any useful code suggestions. I would guess the logic should be about counting and then comparing the count to the previous count.

Last edited by vgersh99; 07-07-2010 at 11:04 AM.. Reason: code tags, PLEASE!
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

row count of all files with more than 0 byte

Hi, Is there any way to get count number of lines in all files which have more than o bytes in current directory for example : in /user/sri/ there are 3 files abc 0 bytes def 5 bytes ghi 10 bytes i need to get wc -l for all files which have > 0 bytes at a time ..is... (6 Replies)
Discussion started by: sri2005
6 Replies

2. UNIX for Dummies Questions & Answers

row count but only number part

hi i am pretty new to unix .i am ETL guy I need a unix script to take row count of a file and write it to another file the problem with wc-l is it include filename also wc -l abc.dat will give me like 1000 abc.dat i just want 1000 to be written can u just take 2 min to write a simple... (1 Reply)
Discussion started by: er_zeeshan05
1 Replies

3. Shell Programming and Scripting

script to take row count

hi i am pretty new to unix .i am ETL guy I need a unix script to take row count of a file and write it to another file the problem with wc-l is it include filename also wc -l abc.dat will give me like 1000 abc.dat i just want 1000 to be written can u just take 2 min to write a simple... (5 Replies)
Discussion started by: er_zeeshan05
5 Replies

4. Shell Programming and Scripting

row count of 60 files in one file

hi all plz some unix guy help me in this i have 60 files which will have some records i want to find the total number of records in all the 60 files like file1 has 60 and file2 has 70 record i want to sum all these and find total row count in 60 files (5 Replies)
Discussion started by: er_zeeshan05
5 Replies

5. Shell Programming and Scripting

Count the delimeter from a file and delete the row if delimeter count doesnt match.

I have a file containing about 5 million rows, in the file there are some records which has extra delimiter at random position. (we dont know the positions), now we have to Count the delimeter from each row and if the count of delimeter is not matching then I want to delete those rows from the... (5 Replies)
Discussion started by: Akumar1
5 Replies

6. Shell Programming and Scripting

To count distinct fields in a row

I have . dat file which contains data in a specific format: 0 3 892 921 342 1 3 921 342 543 2 4 817 562 718 765 3 3 819 562 717 761 i need to compare each field in a row with another field of the same column but different row and cont the... (8 Replies)
Discussion started by: Abhik
8 Replies

7. Shell Programming and Scripting

Count the number or row with same value in a column

This is the source file, we called it errorlist.out 196 server_a server_unix_2 CD 196 server_b server_win_1 CD 196 server_c server_win_2 CD 196 server_bd server_unix_2 CD 196 server_d server_unix_2 CD 196 server_es server_win_1 CD 196 ... (14 Replies)
Discussion started by: sQew
14 Replies

8. UNIX for Advanced & Expert Users

row count

Hi, I want a row count of a file incliding header and trailer If I do cat Filename | wc -l then I am only getting the row count excluding the header and trailer Buit I want the row count including Header and trailer Please help Many thanks in advance, Pragyan (3 Replies)
Discussion started by: prarat
3 Replies

9. Shell Programming and Scripting

Print text between 2 identical strings

hey, i m having a hard time trying to print only the first occurrence between 2 idenicale strings. for the following output: please help me im a noob please im a noob help me noob please help me im a noob please im a noob help me noob (3 Replies)
Discussion started by: boaz733
3 Replies

10. Shell Programming and Scripting

Row Count in .csv file

Hi, I have to find the count of rows starting with "E," in given a.csv file . Sample Data File. E,2333AED,A,MC3,25,31-MAY-18 E,2333AED,A,MC3,25,31-MAY-18 CYMC3 25AED 0000 E,2333CZK,A,MC3,25,31-MAY-18 CYMC3 25CZK 0000 E,2333EUR,A,MC3,25,31-MAY-18... (3 Replies)
Discussion started by: Prabhakar Y
3 Replies
Color::Library::Dictionary::Tango(3pm)			User Contributed Perl Documentation		    Color::Library::Dictionary::Tango(3pm)

NAME
Color::Library::Dictionary::Tango - (Tango) The Tango color palette DESCRIPTION
The Tango icon theme's goal is to make applications not seem alien on any desktop. A user running a multiplatform application should not have the impression that the look is unpolished and inconsistent with what he or she is used to. While this isn't about merging styles of all desktop systems, we do aim to not be drastically different on each platform. The Tango color palette consists of 27 RGB colors. <http://tango.freedesktop.org/Tango_Icon_Theme_Guidelines> COLORS
Aluminium 1 aluminium1 #eeeeec Aluminium 2 aluminium2 #d3d7cf Aluminium 3 aluminium3 #babdb6 Aluminium 4 aluminium4 #888a85 Aluminium 5 aluminium5 #555753 Aluminium 6 aluminium6 #2e3436 Butter 1 butter1 #fce94f Butter 2 butter2 #edd400 Butter 3 butter3 #c4a000 Chameleon 1 chameleon1 #8ae234 Chameleon 2 chameleon2 #73d216 Chameleon 3 chameleon3 #4e9a06 Chocolate 1 chocolate1 #e9b96e Chocolate 2 chocolate2 #c17d11 Chocolate 3 chocolate3 #8f5902 Orange 1 orange1 #fcaf3e Orange 2 orange2 #f57900 Orange 3 orange3 #ce5c00 Plum 1 plum1 #ad7fa8 Plum 2 plum2 #75507b Plum 3 plum3 #5c3566 Scarlet Red 1 scarletred1 #ef2929 Scarlet Red 2 scarletred2 #cc0000 Scarlet Red 3 scarletred3 #a40000 Sky Blue 1 skyblue1 #729fcf Sky Blue 2 skyblue2 #3465a4 Sky Blue 3 skyblue3 #204a87 perl v5.14.2 2011-12-07 Color::Library::Dictionary::Tango(3pm)
All times are GMT -4. The time now is 09:13 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy