Grep unique 1st column


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Grep unique 1st column
# 1  
Old 04-14-2014
Grep unique 1st column

Hello, I'm trying to used awk but am new to this. I have a file like this:
Code:
Bob is a good boy
Bob is a strange person
Bob is a good dancer
Jane can party
Jane is a good girl
Jane is batty

I'd like to get this:
Bob is a good boy
       is a strange person
       is a good dancer
Jane can party
       is a good girl
       is batty

Any help would be appreciated.
# 2  
Old 04-14-2014
Don't understand, From your example data if you search for a 'B' in first column, Do you only want one 'B' output?
# 3  
Old 04-14-2014
Trying to get the output with only 1 Bob and 1 Jane. Thanks!
# 4  
Old 04-14-2014
Do a "man grep" and look at the option:
-m NUM, --max-count=NUM
and see if using that with a 1 is what you want.
# 5  
Old 04-14-2014
You could try something like:
Code:
awk '
$1 == last {
	$1 = ""
	print "      " $0
	next
}
{	last = $1
	print
}' file

If you're using a Solaris/SunOS system, use /usr/xpg4/bin/awk, /usr/xpg6/bin/awk, or nawk instead of /usr/bin/awk.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Count unique column

Hello, I am trying to count unique rows in my file based on 4 columns (2-5) and to output its frequency in a sixth column. My file is tab delimited My input file looks like this: Colum1 Colum2 Colum3 Colum4 Coulmn5 1.1 100 100 a b 1.1 100 100 a c 1.2 200 205 a d 1.3 300 301 a y 1.3 300... (6 Replies)
Discussion started by: nans
6 Replies

2. UNIX for Beginners Questions & Answers

Find unique values but only in column 1

Hi All, Does anyone have any suggestions/examples of how i could show only lines where the first field is not duplicated. If the first field is listed more than once it shouldnt be shown even if the other columns make it unique. Example file : 876,RIBDA,EC2 876,RIBDH,EX7 877,RIBDF,E28... (4 Replies)
Discussion started by: mutley2202
4 Replies

3. Shell Programming and Scripting

Count occurrence of column one unique value having unique second column value

Hello Team, I need your help on the following: My input file a.txt is as below: 3330690|373846|108471 3330690|373846|108471 0640829|459725|100001 0640829|459725|100001 3330690|373847|108471 Here row 1 and row 2 of column 1 are identical but corresponding column 2 value are... (4 Replies)
Discussion started by: angshuman
4 Replies

4. Linux

Print the 1st column and the value in 2nd or 3rd column if that is different from the values in 1st

I have file that looks like this, DIP-17571N|refseq:NP_651151 DIP-17460N|refseq:NP_511165|uniprotkb:P45890 DIP-17571N|refseq:NP_651151 DIP-19241N|refseq:NP_524261 DIP-19241N|refseq:NP_524261 DIP-17151N|refseq:NP_524316|uniprotkb:O16797 DIP-19588N|refseq:NP_731165 ... (2 Replies)
Discussion started by: Syeda Sumayya
2 Replies

5. Shell Programming and Scripting

Sorting unique by column

I am trying to sort, do uniq by 1st column and report this 4 columns tab delimiter table , eg chr10:112174128 rs2255141 2E-10 Cholesterol, total chr10:112174128 rs2255141 7E-16 LDL chr10:17218291 rs10904908 3E-11 HDL Cholesterol chr10:17218291 rs970548 8E-9 TG... (4 Replies)
Discussion started by: fat
4 Replies

6. Shell Programming and Scripting

Grep/Awk on 1st 2 Letters in 2nd Column of File

Hi everyone. I need to change a script (ksh) so that it will grep on the 1st 2 letters in the second column of a 5 column file such as this one: 192.168.1.1 CAXY0_123 10ABFL000001 # Comment 192.168.1.2 CAYZ0_123 10ABTX000002 # Comment 192.168.2.1 FLXY0_123 11ABCA000001 ... (4 Replies)
Discussion started by: TheNovice
4 Replies

7. UNIX for Dummies Questions & Answers

Grep Unique

Hello, I have a file with a list of car makes and specific information for each make. An example is: @Audi:Warranty @Audi:Pricing @Audi:Colors @Acura:Warranty @Acura:Pricing @Acura:Colors and so on through a bunch of makes. I need to make a list in a selection box of just one name of... (4 Replies)
Discussion started by: macbb1117
4 Replies

8. Shell Programming and Scripting

print unique values of a column and sum up the corresponding values in next column

Hi All, I have a file which is having 3 columns as (string string integer) a b 1 x y 2 p k 5 y y 4 ..... ..... Question: I want get the unique value of column 2 in a sorted way(on column 2) and the sum of the 3rd column of the corresponding rows. e.g the above file should return the... (6 Replies)
Discussion started by: amigarus
6 Replies

9. Shell Programming and Scripting

grep for unique value

If i want to grep for a value in a file but display only unique value then which option can i use. ex: Values in the file IP <1.2.3.4> value <2> IP <1.2.3.4> value <2> IP <1.2.3.4> value <3> IP <1.2.3.5> value <1> i should get only the unique value (3 Replies)
Discussion started by: vls1210
3 Replies
Login or Register to Ask a Question