how to combine after comparison


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers how to combine after comparison
# 1  
Old 09-29-2008
how to combine after comparison

hi all,

i have file as below:

N000150100B00|1
N000150100B00|3
E0P2C42100000|2
E0P2C42100000|3
N000150100B00|2
N000150100B00|4
E0P2C42100000|3
E0P2C42100000|3
E0P2C42100000|6

now i want to compare 1st field of all rows with all other row's first field
and if they are same then i have to put that many records in one seperate file.

for example, compare N000150100B00 with all other.. same for all the records.

your help will be appreciated.

thx,
pranav
# 2  
Old 09-30-2008
check if this is what you want:
Code:
sort  -t '|' -k1  /foo/bar | uniq -w 13 -d

# 3  
Old 09-30-2008
.. to a new file with each 1st field and number of occurences:

Code:
sort  -t '|' infile| awk -F "|" '{ arr[$1]+=1 } END{for (ele in arr) { print ele,arr[ele] } }' > newfile

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Combine files

I have n of files with ending with _ZERO.txt need to combine all file ending with _ZERO.txt into 1 file ex: A_ZERO.txt 1 2 B_ZERO.txt 3 4 Output: FINAL.txt 1 2 (3 Replies)
Discussion started by: satish1222
3 Replies

2. Shell Programming and Scripting

Help about comparison

Hello folks, I have two files, which have usernames, I want to see the contents of file1.txt which is missing in file2.txt and another comparison file2.txt contents which is missing in file1.txt. please suggest. file1.txt user u2 u8 a9 p9 p3 u4 z8 aaa ahe oktlo (7 Replies)
Discussion started by: learnbash
7 Replies

3. Shell Programming and Scripting

Combine 2 files

How to cilnd desided output from file1 and file2 with awk. file1 1 2 7 8 9 14 15 16 21 22 23 28 29 30 file2 aa bb cc dd ee ff gg hh ii jj kk ll (3 Replies)
Discussion started by: theshashi
3 Replies

4. UNIX for Dummies Questions & Answers

comparison

hi guys i need a program that can compare a value read from a com-port and one from the terminal. can somebody help me??? using linux kernel 2.6.14-M5 can only use standard function in sh and bash... (5 Replies)
Discussion started by: metal005
5 Replies

5. Shell Programming and Scripting

combine

Dear all i am having text file like xxx|yyy|1|2| zzz|rrr|3|4| www|xxx|>< 5|6|>< jjj|kkk|>< 8|9>< i want to join two lines which are having ' >< ' by taking only two lines at a stretch ...using awk command the result output should be xxx|yyy|1|2| zzz|rrr|3|4| www|xxx|5|6|... (2 Replies)
Discussion started by: suryanarayana
2 Replies

6. Shell Programming and Scripting

$((...)) and $[...] comparison

Does $((mathematical expression)) and $ mean the same? (7 Replies)
Discussion started by: proactiveaditya
7 Replies

7. Shell Programming and Scripting

combine

Hi I am having text file like this 001|ramu|hno221|>< sheshadripuram|delhi|560061>< 002|krishna|hno225|>< newdelhimain|delhi|560061>< i want to combine every two lines as single...line... i.e 001|ramu|hno221|sheshadripuram|delhi|560061 can u pls help me (3 Replies)
Discussion started by: suryanarayana
3 Replies

8. Shell Programming and Scripting

need some help..Comparison

I need some help which would probably be for most of you a simple script. I need to read in the data from a .dat file and then compare avg to see who is the highest avg. Here is my script so far. #!/bin/ksh #reading in the data from lab3.dat filename=$1 while read name o1 o2 o3 o4 o5 o6... (0 Replies)
Discussion started by: bluesilo
0 Replies

9. Shell Programming and Scripting

Need To Combine 2 Files

I have 2 files that I need to combine. One file is looks like this: 71664107;1;1;05-FEB-07;12-FEB-07; The other file looks like this: U;71664107;dummy;Pirovano;M;04-SEP-75;Georgia;MI;1;1;31;S;S;;;Y;05-02-2007;0;12-FEB-07; I need to combine both files together. I need the shorter... (4 Replies)
Discussion started by: goodmis
4 Replies

10. Filesystems, Disks and Memory

comparison

can anyone point me to a comparison of *nix file systems ? i think i prefer a journalling fs but i would like to see a comparison between several fs's before i make up my mind (2 Replies)
Discussion started by: cnf
2 Replies
Login or Register to Ask a Question