need help sorting/deleting non-unique things


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers need help sorting/deleting non-unique things
# 8  
Old 09-09-2009
Quote:
Originally Posted by sanjay.login
yes vgres it is working fine.
and giving the correct output
1 1 1 1 1 1 1 4 1 1 1 1_4 4_1
Code:
$ sort -k 12 numbers.txt|uniq -f 11 -c|awk -f " " '$1==1{print}'|cut -f 2-
awk: can't open

What's in red?

Last edited by vgersh99; 09-09-2009 at 05:53 PM..
# 9  
Old 09-09-2009
sorry actually i have given the -f option instead of -F option
the code is :
$ sort -k 12 numbers.txt|uniq -f 11 -c|awk -F " " '$1==1{print}'|cut -f 2- >new_file



and i gave a space in those double quoues
regards,
Sanjay
# 10  
Old 09-09-2009
Quote:
Originally Posted by sanjay.login
sorry actually i have given the -f option instead of -F option
the code is :
$ sort -k 12 numbers.txt|uniq -f 11 -c|awk -F " " '$1==1{print}'|cut -f 2- >new_file



and i gave a space in those double quoues
regards,
Sanjay
you don't have to specify the FS, as it's space OR tab by default - you can drop the '-F' specification.
Furthermore, I'm not sure if this is what the OP is looking for, because somehow you're checking to see if the first field is '1'. I'm not sure that's what the OP is after.
Let's see if the OP validates the code/results.
I get the following output with your code - not the leading spaces:
Code:
   1 1 1 1 1 1 1 2 1 2 1 1 1_2 2_1
   1 1 1 1 1 1 1 1 4 1 1 1 1_4 4_1

# 11  
Old 09-09-2009
the first field is the frequency(due to uniq -c option) of the records which i serched for $1=1 and then used cut -f 2- which will exclude the first field( the frequecy field). The logic is that.

thanks and regards,
Sanjay
# 12  
Old 09-09-2009
I also do not get the correct output with your code:
Code:
> sort -k 12 numbers.txt|uniq -f 11 -c|awk -F " " '$1==1{print}'|cut -f 2-
   1 1 1 1 1 1 1 1 4 1 1 1 1_4 4_1

I don't know about every version of 'cut' out there but mine has a default delimiter of <tab>. So, to make this work on my system, the 'cut' needs to specify the delimiter. And because it counts each delimiter character, and this line includes leading spaces, -f2- doesn't cut it either.

My perl solution didn't have this problem. To get this solution to work on my system, it has to be like this:
Code:
> sort -k 12 numbers.txt|uniq -f 11 -c|awk -F " " '$1==1{print}'|cut -f 5- -d " "
1 1 1 1 1 1 1 4 1 1 1 1_4 4_1

# 13  
Old 09-09-2009
thanks to let me know regarding the output ,i ran again and also facing the same problem(not getting the correct out put).i am trying to correct the code.

thanks again to vgresh and vi_curious
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

Sorting out unique values from output of for loop.

Hi , i have a belwo script which is used to get sectors per track value extarcted from Solaris machine: for DISK in /dev/dsk/c*t*d*s*; do value=`prtvtoc "$DISK" | sed -n -e '/Dimensions/,/Flags/{/Dimensions/d; /Flags/d; p; }' | sed -n -e '/sectors\/track/p'`; if ; then echo... (4 Replies)
Discussion started by: omkar.jadhav
4 Replies

3. UNIX for Dummies Questions & Answers

Sorting and saving values based on unique entries

Hi all, I wanted to save the values of a file that contains unique entries based on a specific column (column 4). my sample file looks like the following: input file: 200006-07file.txt 145 35 10 3 147 35 12 4 146 36 11 3 145 34 12 5 143 31 15 4 146 30 14 5 desired output files:... (5 Replies)
Discussion started by: ida1215
5 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. UNIX for Dummies Questions & Answers

Deleting words and sorting

I have a file that looks some like this: I need to delete most of the information and sort the rest in such way that I get the following output file Any help will be greatly appreciated (3 Replies)
Discussion started by: Xterra
3 Replies

6. Shell Programming and Scripting

Need help comparing two files and deleting some things in those files!

So I have two files: File1 pictures.txt 1.1 1.3 dance.txt 1.2 1.4 treehouse.txt 1.3 1.5 File2 pictures.txt 1.5 ref2313 1.4 ref2345 1.3 ref5432 1.2 ref4244 dance.txt 1.6 ref2342 1.5 ref2352 1.4 ref0695 1.3 ref5738 1.2 ref4948 1.1 treehouse.txt 1.6 ref8573 1.5 ref3284 1.4 ref5838... (24 Replies)
Discussion started by: linuxkid
24 Replies

7. Shell Programming and Scripting

Finding unique entries without sorting

Hi Guys, I have two files that I am using: File1 is as follows: wwe khfgv jfo jhgfd hoaha hao lkahe This is like a master file which has entries in the order which I want. (4 Replies)
Discussion started by: npatwardhan
4 Replies

8. 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

9. UNIX for Dummies Questions & Answers

Sorting with unique piping for a lot of files

Hi power user, if I have this file: file1.txt: 1111 1111 2222 2222 3333 3333 3333 4444 4444 4444 when I run the sort file1.txt | uniq > data1.txt the result is (2 Replies)
Discussion started by: anjas
2 Replies

10. Shell Programming and Scripting

sorting file and unique commnad..

hello everyone.. I was wondering is there a effective way to sort file that contains colomns and numeric one. file 218900012192 8938929 8B8DF3664 1E7E2D59D5 0000 26538 1234 74024415 218900012979 8938929 8B8DF3664 1E7E2D59D5 0000 26538 1234 74024415 218900012992 8938929 8B8DF3664... (2 Replies)
Discussion started by: amon
2 Replies
Login or Register to Ask a Question