LinuxQuestions.org
Visit the LQ Articles and Editorials section
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 01-14-2008, 01:30 PM   #16
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 718

Rep: Reputation: 72

Hi.

Here are some timings for many of the suggestions:
Code:
% ./do-time

 Sample of input /tmp/one-mb.txt (1013897 characters):
     1  Sun Jan 13 08:38:16 CST 2008
     2
     3  Egghead genial trident Ostrander snuggly.  Dumpy smuggle ptict grirgadsy
     4  Mallory.  Herman Melville Airway fight ten Sproul spoken morass?
     5  Swerve ostracism cap schema betwixt passenger Himalaya frivolity.
   ...
 16562
 16563  Ago grapevine eradicable bedim electret cyanate component?  Moby Dick
 16564  Nineveh stearate Amsterdam other pronounce octuwoft wharf kidnapped
 16565  catatonia.  Posterior emphatic weapon today Freeport krobs strulchuct
 16566  Rodriguez.

 Timing for perl (general (first run)):
 (debug, pattern is :,:)
 (debug, read 16566 lines.)
 (debug, matched and changed at line 16501)
0.03user 0.00system 0:00.05elapsed 70%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+1450minor)pagefaults 0swaps

 Timing for perl (general (second run)):
 (debug, pattern is :,:)
 (debug, read 16566 lines.)
 (debug, matched and changed at line 16501)
0.03user 0.00system 0:00.04elapsed 75%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+1450minor)pagefaults 0swaps

 Timing for perl (general, re-write):
0.02user 0.01system 0:00.05elapsed 67%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+1224minor)pagefaults 0swaps

 Timing for sed:
0.05user 0.00system 0:00.06elapsed 82%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+491minor)pagefaults 0swaps

 Timing for awk:
0.06user 0.00system 0:00.08elapsed 86%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+1181minor)pagefaults 0swaps

 Timing for perl (one-liner):
0.02user 0.00system 0:00.03elapsed 67%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+668minor)pagefaults 0swaps

 Timing for perl (one-liner slurp):
0.01user 0.00system 0:00.02elapsed 66%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+1948minor)pagefaults 0swaps

 Timing for perl (one-liner reverse slurp):
0.02user 0.00system 0:00.03elapsed 81%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+1514minor)pagefaults 0swaps
Even with a 1 MB file, the timings are close enough such that the decision would be based on factors other than time.

If I were putting this into a Makefile, I'd probably choose osor's slurp reverse one-liner: it's short, fast, and doesn't assume the next-to-last line. I'd fiddle around with it to try to get it to re-write in-place (I tried it with "-i", but it didn't work for me -- cleared the file, wrote to STDOUT).

Best wishes ... cheers, makyo
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
How to remove first 2 lines of a file in a script nazs Programming 16 02-19-2007 07:08 AM
need to replace spaces with comma (ascii file) ferradura Linux - Software 3 02-02-2007 08:39 PM
remove text from file with script paul_mat Linux - Software 3 11-17-2005 12:21 PM
Sed(?); Appending a comma-delineated file ice_hockey Linux - General 2 05-27-2005 08:42 AM
comma delimited file cdragon Programming 5 06-21-2002 07:55 PM


All times are GMT -5. The time now is 12:01 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration