Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Apr 27 02:02:36 MEDIA 14 LINK 3 : AVAILABLE
Apr 27 02:02:36 MEDIA 14 LINK 7 : AVAILABLE
Apr 27 02:02:37 MEDIA 14 LINK 0 : AVAILABLE
Apr 27 02:02:37 MEDIA 14 LINK 1 : AVAILABLE
Apr 27 02:02:37 MEDIA 14 LINK 2 : AVAILABLE
Apr 27 02:02:37 MEDIA 12 LINK 4 : AVAILABLE
Apr 27 02:02:37 MEDIA 14 LINK 5 : AVAILABLE
Apr 27 02:02:37 MEDIA 14 LINK 6 : AVAILABLE
Apr 27 04:43:20 MEDIA 13 LINK 0 : UNAVAILABLE
Apr 27 04:43:20 MEDIA 03 LINK 1 : UNAVAILABLE
Apr 27 04:43:20 MEDIA 13 LINK 2 : UNAVAILABLE
Apr 27 04:43:20 MEDIA 13 LINK 3 : UNAVAILABLE
Apr 27 04:43:20 MEDIA 11 LINK 4 : UNAVAILABLE
Apr 27 04:43:20 MEDIA 13 LINK 5 : UNAVAILABLE
Apr 27 04:43:20 MEDIA 13 LINK 6 : UNAVAILABLE
Apr 27 04:43:20 MEDIA 13 LINK 7 : UNAVAILABLE
Apr 27 04:43:20 MEDIA 13 : UNAVAILABLE
Apr 27 04:43:20 MEDIA 14 LINK 0 : UNAVAILABLE
Apr 27 04:43:20 MEDIA 14 LINK 2 : UNAVAILABLE
Apr 27 04:43:20 MEDIA 07 LINK 5 : UNAVAILABLE
Apr 27 04:43:20 MEDIA 14 LINK 6 : UNAVAILABLE
Apr 27 04:43:20 MEDIA 14 LINK 7 : UNAVAILABLE
Apr 27 04:43:23 MEDIA 13 : AVAILABLE
The output I want is:
MEDIA 14
MEDIA 12
MEDIA 13
MEDIA 03
MEDIA 11
MEDIA 07
Using arrays might be too complicated. Use awk's pattern search, print appropriate fields and pipe it through sort.
Hope this helps.
EDIT: @pan64: That will print all the fields records, not just those that are UNAVAILABLE
Druuna,
PAN64 is correct. awk has a default field separator of <space>. With this, by printing field 4 and 5, he will get the required fields.
PAN64: I had forgotten about -u on the sort, thank you for the reminder. The -u tells sort to print only unique records. Saves you piping the output to uniq.
fist, just use
grep 'Apr 27.*MEDIA.*' myfile
without cat and pipe.
second, uniq does not work because those lines contain times. So awk will drop unnecessary parts (awk can also be used instead of grep), and uniq or sort will do the rest.
Since there is this useless cat hanging around, I'll chime in with another way to skin it.
grail's example is obviously better, but i sometimes feel cut is under appreciated in favour of sed/awk etc so I thought id chime in with an example using cut.
Code:
fukawi1 ~/tmp # cut -f4-5 -d' ' data | sort -u
MEDIA 03
MEDIA 07
MEDIA 11
MEDIA 12
MEDIA 13
MEDIA 14
fukawi1 ~/tmp # cut -f4-5 -d' ' data | awk '!($0 in a){a[$0];print}'
MEDIA 14
MEDIA 12
MEDIA 13
MEDIA 03
MEDIA 11
MEDIA 07
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.