match and sort using awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting match and sort using awk
# 8  
Old 03-24-2010
Quote:
Originally Posted by rdcwayx
Code:
awk 'FNR==NR {a[$2]++;next} {if (a[$1]>0) {print $1,$1;a[$1]--} else {print $1}} ' input input |sort

Ignore mine -- this works better. Perl guys should not talk about awk... Smilie
# 9  
Old 04-12-2010
one more request

Thanks a lot to rdcwayx and drewk

sending the same file two times was a smart idea

but what if i have some thing like this a string attached to the key word
Code:
apple    abc    cat    wegsdfg
in    def    rat    wrtyery
out    gasdf    sky    ertyenr
cat    asdfas    pen    etynu
rat    asdf    ball    dyunr
sky    asdf    cpu    wtyvshb
pen    asdfwr    linux    stryehbr
ball    wert    unix    sbysdfhb
cpu    wertj    paper    srtbvh
linux    erdeh    phone    shvgfhhj
unix    eryy 
paper    eryd 
phone    12345 
phone    34567 
paper    25347 
unix    4574576 
cpu    3745634

and i wanted a similar out put like before but along with the strings

Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to print match or non-match and select fields/patterns for non-matches

In the awk below I am trying to output those lines that Match between file1 and file2, those Missing in file1, and those missing in file2. Using each $1,$2,$4,$5 value as a key to match on, that is if those 4 fields are found in both files the match, but if those 4 fields are not found then missing... (0 Replies)
Discussion started by: cmccabe
0 Replies

2. Shell Programming and Scripting

awk to update file based on partial match in field1 and exact match in field2

I am trying to create a cronjob that will run on startup that will look at a list.txt file to see if there is a later version of a database using database.txt as the source. The matching lines are written to output. $1 in database.txt will be in list.txt as a partial match. $2 of database.txt... (2 Replies)
Discussion started by: cmccabe
2 Replies

3. Shell Programming and Scripting

awk to match field between two files and use conditions on match

I am trying to look for $2 of file1 (skipping the header) in $2 of file2 (skipping the header) and if they match and the value in $10 is > 30 and $11 is > 49, then print the line from file1 to a output file. If no match is foung the line is not printed. Both the input and output are tab-delimited.... (3 Replies)
Discussion started by: cmccabe
3 Replies

4. Shell Programming and Scripting

awk if match

Hi, This is the file content: #160814 20:43:00 server id 2 end_log_pos 169934694 Query thread_id=8927407 exec_time=0 error_code=0 use sun_final/*!*/; SET TIMESTAMP=1471207380/*!*/; DELETE FROM `top_pack` WHERE `top_pack`.`id` = 3023 Trying like:awk... (5 Replies)
Discussion started by: ashokvpp
5 Replies

5. UNIX for Dummies Questions & Answers

awk - (URGENT!) Print lines sort and move lines if match found

URGENT HELP IS NEEDED!! I am looking to move matching lines (01 - 07) from File1 and 77 tab the matching string from File2, to File3.txt. I am almost done but - Currently, script is not printing lines to File3.txt in order. - Also the matching lines are not moving out of File1.txt ... (1 Reply)
Discussion started by: High-T
1 Replies

6. Shell Programming and Scripting

awk sort

input file abc1 abc23 abc12 abc15 output abc1 abc12 abc15 abc23 (9 Replies)
Discussion started by: yanglei_fage
9 Replies

7. UNIX for Dummies Questions & Answers

awk display the match and 2 lines after the match is found.

Hello, can someone help me how to find a word and 2 lines after it and then send the output to another file. For example, here is myfile1.txt. I want to search for "Error" and 2 lines below it and send it to myfile2.txt I tried with grep -A but it's not supported on my system. I tried with awk,... (4 Replies)
Discussion started by: eurouno
4 Replies

8. Shell Programming and Scripting

Sort in AWK

Hi, I usually use Access to sort data however for some reason its not working. Our systems guys and myself cannot figure it out so ive tried to use AWK to do the sorting. The file is made up of single lines in the format ... (4 Replies)
Discussion started by: eknryan
4 Replies

9. Homework & Coursework Questions

awk sort help

1. The problem statement, all variables and given/known data: I dont know what I do wrong, I am trying to create shell programming database: I have this command first: && > $fname ... echo $Name:$Surname:$Agency:$Tel:$Ref: >> $fname then I have echo " Name Surname Agency Tel... (2 Replies)
Discussion started by: jeht
2 Replies

10. Shell Programming and Scripting

sort & match multiple files

Hi, I have some question and need some guidance how to sort and match multiple files. 1. all the data in the files are numbers e.g. 1234567 1584752 2563156 2. each sorted file have their own ouput. e.g. test.csv -> test_sorted.csv 3. Then, I need to match all... (4 Replies)
Discussion started by: nazri76
4 Replies
Login or Register to Ask a Question