Help me in this script fast


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help me in this script fast
# 1  
Old 02-10-2013
Help me in this script fast

i have log files that represent names, times and countries,
each name come once in country but may in diff times
i need at end each name visited which country and its [ last time of visit ]


Code:
USA | Tony | 12:25:22:431
Italy | Tony | 09:33:11:212    ****
Italy| John | 08:22:12:349 
France | Adam | 14:22:42:981
Italy | Tony | 08:22:42:212    ****
Italy | Tony | 04:22:42:212   ****
Italy | Tony | 18:22:42:212   ****
USA | Adam | 14:22:42:981

i want the output to be :

Code:
USA | Tony | 12:25:22:431
Italy | Tony | 18:22:42:212  / we discarded other as this is the latest time/ 
Italy| John | 08:22:12:349
France | Adam | 14:22:42:981
USA | Adam | 14:22:42:981

i have tired this code but it take very huge time so help me to get more smarter script or take a little time
Code:
while [1]
do 
for name in file.txt | cut -d/| -f2 | uniq -d 
do 
grep name file.txt | sort -n -k2  | tail -1 >> output.txt 
done 
done

but this script output is


Code:
Italy | Tony | 18:22:42:212   
Italy| John | 08:22:12:349
France | Adam | 14:22:42:981


which is wrong , it only get least day per name.

Last edited by Scrutinizer; 02-10-2013 at 04:16 PM.. Reason: code tags
# 2  
Old 02-10-2013
I just tried this with GNU sort and awk and it seems to work fine:
Code:
sort -r -k5 t3 | awk '!a[$1,$3]++'

PS: This record has no space between "Italy" and the pipe character.
Code:
Italy| John | 08:22:12:349

This User Gave Thanks to user8 For This Post:
# 3  
Old 02-10-2013
Everyone at the UNIX and Linux Forums gives their best effort to reply to all questions in a timely manner. For this reason, posting questions with subjects like "Urgent!" or "Emergency" and demanding a fast reply are not permitted in the regular forums.

For members who want a higher visibility to their questions, we suggest you post in the Emergency UNIX and Linux Support Forum. This forum is given a higher priority than our regular forums.

Posting a new question in the Emergency UNIX and Linux Support Forum requires forum Bits. We monitor this forum to help people with emergencies, but we do not not guarantee response time or best answers. However, we will treat your post with a higher priority and give our best efforts to help you.

If you have posted a question in the regular forum with a subject "Urgent" "Emergency" or similar idea, we will, more-than-likely, close your thread and post this reply, redirecting you to the proper forum.

Of course, you can always post a descriptive subject text, remove words like "Urgent" etc. (from your subject and post) and post in the regular forums at any time.


Thank you.

The UNIX and Linux Forums
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

fast sequence extraction

Hi everyone, I have a large text file containing DNA sequences in fasta format as follows: >someseq GAACTTGAGATCCGGGGAGCAGTGGATCTC CACCAGCGGCCAGAACTGGTGCACCTCCAG GCCAGCCTCGTCCTGCGTGTC >another seq GGCATTTTTGTGTAATTTTTGGCTGGATGAGGT GACATTTTCATTACTACCATTTTGGAGTACA >seq3450... (4 Replies)
Discussion started by: Fahmida
4 Replies

2. Shell Programming and Scripting

Small fast question

just to confirm du from sh show sizes as multiples of 512 byte right? (4 Replies)
Discussion started by: Nick1097
4 Replies

3. Shell Programming and Scripting

Expect script exiting too fast if used without interact.

Hi I'm working on an Expect script that is supposed to log-into a remote server and run some steps and exit. In the script I first spawn a 'ssh' session to the server and then after logging in I 'send' all the necessary steps ( with a '\r' at the end, so that they get automatically executed the... (3 Replies)
Discussion started by: clakkad
3 Replies

4. Solaris

How do you ufsrestore the fast way?

hi, on my sol9 box i create my backup using the below command: /usr/sbin/ufsdump 0uf /dev/rmt/0n /u1 /usr/sbin/ufsdump 0uf /dev/rmt/0n /u2 /usr/sbin/ufsdump 0uf /dev/rmt/0n /u3 /usr/sbin/ufsdump 0uf /dev/rmt/0n /u4 now on the new sol10 box, to restore i use this commands: cd /u1... (3 Replies)
Discussion started by: pinoy43v3r
3 Replies

5. Shell Programming and Scripting

Performing fast searching operations with a bash script

Hi, Here is a tough requirement , to be served by bash script. I want to perform 3,00,000 * 10,000 searches. i.e. I have 10,000 doc files and 3,00,000 html files in the file-system. I want to check, which of the doc files are referred in any html files. (ex- <a href="abc.doc">abc</a>)... (3 Replies)
Discussion started by: jitendriya.dash
3 Replies

6. Solaris

what is that 1 in the instruction!~ (please help fast)

Hi all, make_lofs /.cdrom/<something>/<something> 1 what does this instruction mean? Note:both the "something" are obviously different . I would like to know what that 1 means, the rest of the instruction is clear!! Thanks (6 Replies)
Discussion started by: wrapster
6 Replies

7. UNIX for Dummies Questions & Answers

What's the fast way to delete these files?

Hi, I had this request from user which I completed by using rm for all these files but I am wondering if there was way to finish it faster rather going through one file at a time. Please check attached text file to see file names. Thanks! (4 Replies)
Discussion started by: tonyvirk
4 Replies

8. UNIX for Advanced & Expert Users

Need help fast

I am trying to reset the IP address on a Unix HP box here in my office and I am stuck in this EM100 mode and cant issue any commands. Any help would be great. By the way I no zero about unix. Thanks (0 Replies)
Discussion started by: zx6ninja
0 Replies
Login or Register to Ask a Question