LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-16-2012, 08:58 AM   #16
masavini
Member
 
Registered: Jun 2008
Posts: 285

Original Poster
Rep: Reputation: 6

this version works, but with a different behaviour with delimiters and multi-lines variables...

i mean:
Code:
$ echo -e "bubu gaga bubu\ndede dudu-dede" | awk '{ORS=RT}!_[$0]++' RS='[-\n ]'
bubu gaga dede dudu-
the output should be:
bubu gaga
dede dudu

i guess the first proposed solution is still the best one...
Quote:
Code:
awk 'BEGIN{FS = "[ -]"}{ while(++i<=NF) printf (!a[$i]++) ? $i " " : ""; i=split("",a); print "" }'
thank you all anyway!
 
Old 05-16-2012, 11:08 AM   #17
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
Well if you have it, ruby is probably cleaner:
Code:
echo -e "bubu gaga bubu-dede\ndede dudu-dede" | ruby -F"[- \n]" -ane 'puts $F.uniq.join(" ")'
 
Old 05-16-2012, 07:34 PM   #18
masavini
Member
 
Registered: Jun 2008
Posts: 285

Original Poster
Rep: Reputation: 6
and which command do you think it's faster? awk or ruby?
i use it thousands times every day...

ps: i just hope this question is not too stupid...

Last edited by masavini; 05-16-2012 at 07:43 PM.
 
Old 05-17-2012, 12:17 AM   #19
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
No question is stupid when asked honestly

I would have to say that I am not 100% sure. In the trivial cases we have been using I would say whichever takes your fancy, which for me would be the ruby only due to less typing
If you have a decent amount of data to run them both on, simply pre-pend the time function prior to call and it will give you results, ie:
Code:
time ruby -F"[- \n]" -ane 'puts $F.uniq.join(" ")' file
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] duplicated title line in Ubuntu 11.10 peter576 Linux - Newbie 1 12-03-2011 10:50 AM
[SOLVED] Remove line break if next line does not start with "PX" joje47 Programming 8 05-25-2011 08:50 AM
deleting duplicate lines without deleting first instance of the duplicated line jkeertir Linux - Newbie 2 02-07-2011 06:55 AM
Get duplicated names listed in /etc/passwd including the line number... shorte85 Linux - Newbie 6 03-23-2009 10:52 AM
How to remove duplicated launcher on gnome panel menu? openfun Debian 8 10-06-2005 06:49 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration