Unique cell vaules in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unique cell vaules in a file
# 1  
Old 01-16-2006
Unique cell vaules in a file

I have a file in which I have records as follows
--------------------------------------------------------------------------
2-sister-birmbb-s0005.ftip002590790.vpn-nte.bt.net BRI0 0 0 0
aber-con-dyce-s0006.ftip002732992.vpn-nte.bt.net ATM0 0 0 0
--------------------------------------------------------------------------
The first row is a router name. I want the count of these router names.
wc -l filename gives me the count of line in the file but, on some lines these router names are repeated. So actually i want the count of unique router names in the file. How can I do that?

Regards,
Rahul.
# 2  
Old 01-16-2006
nawk '! ($1 in arr) {cnt++;arr[$1]} END {printf("routers->[%d]\n", cnt)}' myFile
# 3  
Old 01-17-2006
sort -u filename | wc -l
# 4  
Old 01-17-2006
In my understanding you need soln to have a count for each occurance of a router name. As you have file f1 as below :
-------------
r
p
q
p
p
-------------

sort f1 | uniq -c - will produce o/p as below :

3 p
1 q
1 r
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extracting vaules from end of string

I'm trying to write a script which will calculate percentages from a printer. I have a command snmpwalk -v1 -c public 192.168.0.20 1.3.6.1.2.1.43.11.1.1.9.1.1 which returns (current ink level): iso.3.6.1.2.1.43.11.1.1.9.1.1 = INTEGER 235 then a similar command which returns similar output but... (7 Replies)
Discussion started by: leshy93
7 Replies

2. Shell Programming and Scripting

Parse excel file with html on each cell

<DIV><P>Pré-condição aceder ao ecrã Home do MRS.</P></DIV><DIV><P>OK.</P></DIV><DIV><P>Seleccionar Pesquisa de Recepção Directa.</P></DIV><DIV><P>Confirmar que abriu ecrã de Recepção Directa.</P></DIV><DIV> (6 Replies)
Discussion started by: oliveiraum
6 Replies

3. UNIX for Dummies Questions & Answers

Trying To Write File Contents To Specfic .csv Cell

Hi, I'm attempting to write the entire contents of a file to a specific .csv cell. So far have only a nawk one liner that will write a value into a specific .csv cell. Trying to use man page but can't seem to get any farther. Any help would be appreciated. nawk -v r=2 -v c=3 -v val=5 -F,... (7 Replies)
Discussion started by: jimmyf
7 Replies

4. Shell Programming and Scripting

Change unique file names into new unique filenames

I have 84 files with the following names splitseqs.1, spliseqs.2 etc. and I want to change the .number to a unique filename. E.g. change splitseqs.1 into splitseqs.7114_1#24 and change spliseqs.2 into splitseqs.7067_2#4 So all the current file names are unique, so are the new file names.... (1 Reply)
Discussion started by: avonm
1 Replies

5. Shell Programming and Scripting

Extract last cell of csv file

How do I extract the last cell in a column of a csv file using linux shell scripting? Or alternatively, how do I get the number of cells of a csv file? (2 Replies)
Discussion started by: locoroco
2 Replies

6. UNIX for Advanced & Expert Users

How to add two values in the same cell of CSV file

I need help to create a csv file with Unix command. In csv file, i need to put two values in the same cell. Rite now, whts happening is, if i put 2 values in the same cell, its comming as " asd, zxc" but i want it in different line but in same cell. asd zxc Please reply me ASAP. (1 Reply)
Discussion started by: Prashant Jain
1 Replies

7. Shell Programming and Scripting

get part of file with unique & non-unique string

I have an archive file that holds a batch of statements. I would like to be able to extract a certain statement based on the unique customer # (ie. 123456). The end for each statement is noted by "ENDSTM". I can find the line number for the beginning of the statement section with sed. ... (5 Replies)
Discussion started by: andrewsc
5 Replies

8. UNIX for Dummies Questions & Answers

File need to send to xls as one complete cell

Hi every one, I have a file of ten lines in unix i want to send the file to my mail as .xls and the clause over here is it should send in only one cell .. I am aware of uuencode rest rest.xls | mail -s "testing" mailid But this would send me data into seperate cells (5 Replies)
Discussion started by: rakesh_pagadala
5 Replies

9. Shell Programming and Scripting

How to edit particular cell of csv file using shell script

I have one csv file and in that I want update particular cell. I know the row and coloumn number for that respective. Please help me... (6 Replies)
Discussion started by: deepak_p86
6 Replies

10. UNIX for Dummies Questions & Answers

reading vaules from a text file.

say i have a text file called "input.txt" 1 5 2 10 3 15 4 20 and say I wanted to read the row 3 from column 2 how would i go about it. I guess I would use "awk" but I'm not sure how. (2 Replies)
Discussion started by: THM
2 Replies
Login or Register to Ask a Question