Help with awk for selecting lines in a file avoiding repetition


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with awk for selecting lines in a file avoiding repetition
# 1  
Old 11-26-2012
Help with awk for selecting lines in a file avoiding repetition

Hello,

I am using Awk in UBUNTU 12.04.

I have a file as following with 48,432,354 lines and 4 fields.
The file has this structure (There are repetitions of the first column in several lines)
Code:
AB_14 S54 A G
AB_14 S55 A A
AB_14 S56 G G
GO_15 S45 T A
GO_15 S46 A A
PT_16  S33 C C
PT_16  S34 G A
PT_16  S35 T T
PT_16  S36 T A

What I want to have as an outcome is this:
Code:
AB_14 S54 A G
GO_15 S45 T A
PT_16  S33 C C

That is to have a file only with the first lines of the first file. To mention, I have a file only with the list of names of the first file like this if that can be useful.
Code:
AB_14 
GO_15 
PT_16

Thank you very much in advance.

Last edited by Franklin52; 11-26-2012 at 06:50 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 11-26-2012
Code:
awk '!a[$1]++' infile

This User Gave Thanks to complex.invoke For This Post:
# 3  
Old 11-26-2012
PERFECT! It worked, thank you very very much.
This User Gave Thanks to Homa For This Post:
# 4  
Old 11-26-2012
Hi Mr complex,

could you please let me know how it works ?


awk '!a[$1]++' infile
This User Gave Thanks to only4satish For This Post:
# 5  
Old 11-26-2012
https://www.unix.com/shell-programmin...using-awk.html
Only difference, is that in this case, only look at column #1
This User Gave Thanks to Jotne For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Selecting A Block Of Data From A File (AWK)

Ladles and Jellyspoons,I am trying to use, unsucessfully I might add, awk to strip a large block of information from and audit output.The format resembles the following:-----------------------------------------------------------Event: execveTime: ... (3 Replies)
Discussion started by: proc1269
3 Replies

2. Shell Programming and Scripting

Help with selecting column with awk for a txt file generated by excel

I am new to scripting/programming, so I apologize for any novice questions. I have a tab delimited text file that was saved from excel xls file. I am trying to select only the third column using awk command. My command line is as below: cat test.txt | awk '{print $3}' However, above... (8 Replies)
Discussion started by: SangLad
8 Replies

3. Shell Programming and Scripting

selecting lines using awk

I have a file which contains five hundred thousand lines (500,000). I want to select lines of every 1000 lines from that file using AWK. I can think something like this in bash as below: for lines in {0..500000..1000} do ........ ........ done But I want to use AWK. I do not know how to... (4 Replies)
Discussion started by: vjramana
4 Replies

4. Shell Programming and Scripting

Selecting specific 'id's from lines and columns using 'SED' or 'AWK'

Hello experts, I am new to this group and to 'SED' and 'AWK'. I have data (text file) with 5 columns (C_1-5) and 100s of lines (only 10 lines are shown below as an example). I have to find or select only the id numbers (C-1) of specific lines with '90' in the same line (of C_3) AND with '20' in... (6 Replies)
Discussion started by: kamskamu
6 Replies

5. Shell Programming and Scripting

Selecting lines of a file

Say I wanted to select the 5th line of a file without knowing the context of the file. Would I use grep and pipe it into wc or is there a more simple way of doing this? (3 Replies)
Discussion started by: puttster
3 Replies

6. Shell Programming and Scripting

Selecting a range of Lines

Hi All, Is there a way to get a range of lines from a file??? I want to search through a set of scripts and need to select the group of lines which do the FTP. Say, Line1 Line2 ftp SERVER user UNAME PASS send FILE_TO_BE_SENT close Line3 Line4 Line5 ftp SERVER1 user USER1 PASS1... (6 Replies)
Discussion started by: beinthemiddle
6 Replies

7. Shell Programming and Scripting

Selecting lines with sed

Hi all, I have a file with special characters like this file1 691775025 qJ8^Z^Y{ 2004-08-23E P 100.00 45585025 0527541139295037342008-07-25OEP 100.00 6983025 B<9D>x<^F^Xb 2004-11-16SPP 100.00 I need a sed command to print the lines which don't have special characters.ie., only line 2... (9 Replies)
Discussion started by: allinshell
9 Replies

8. Shell Programming and Scripting

about selecting lines

Hello , i got text file like that' C:\Users\Public\Pictures\Sample Pictures\aa.jpg C:\Users\Public\Pictures\Sample Pictures\thumb.jpg C:\Users\Public\Pictures\vv\cc.jpg C:\Users\Public\Pictures\Sample Pictures\ee.jpg C:\Users\Public\aa\Sample Pictures\cvswsr.jpg... (1 Reply)
Discussion started by: davidkhan
1 Replies

9. Shell Programming and Scripting

Selecting Lines on text file

Hi All, I am creating a script that sends log data from text files to a Database and I will like to read sugestions, as I think that there might be better ways to achive this than with my shell script; maybe perl or I don't know, but I will like to read some sugestions. The log is from... (10 Replies)
Discussion started by: oconmx
10 Replies

10. UNIX for Dummies Questions & Answers

Help with selecting specific lines in a large file

Hello, I need to select the 3 lines above as well as below a search string, including the search string. I have been trying various combinations using sed command without any success. Can anuone help please. Thanking (2 Replies)
Discussion started by: tansha
2 Replies
Login or Register to Ask a Question

Featured Tech Videos