* [9fans] text utility
@ 2003-07-21 11:45 pac
2003-07-21 11:52 ` boyd, rounin
0 siblings, 1 reply; 12+ messages in thread
From: pac @ 2003-07-21 11:45 UTC (permalink / raw)
To: 9fans
Hi, friends,
I've put a small text utility "tac" (meaning "reverse cat", i.e., write out
lines with reverted order of chars) onto the neXt Archive
ftp://ftp.gli.cas.cz/gli/cejchan/neXt/text/
It may look like toy but I use it when genes are transcribed from the
complementary DNA string. If somebody would like to teach it runes,
(s)he is welcome!
Enjoy, if you can!
++pac.
---
Odchozí zpráva neobsahuje viry.
Zkontrolováno antivirovým systémem AVG (http://www.grisoft.cz).
Verze: 6.0.502 / Virová báze: 300 - datum vydání: 18.7.2003
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [9fans] text utility
2003-07-21 11:45 [9fans] text utility pac
@ 2003-07-21 11:52 ` boyd, rounin
2003-07-22 14:09 ` rog
0 siblings, 1 reply; 12+ messages in thread
From: boyd, rounin @ 2003-07-21 11:52 UTC (permalink / raw)
To: 9fans
err, what happened to rev(1)?
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [9fans] text utility
2003-07-21 11:52 ` boyd, rounin
@ 2003-07-22 14:09 ` rog
2003-07-22 14:35 ` boyd, rounin
2003-07-22 23:28 ` Geoff Collyer
0 siblings, 2 replies; 12+ messages in thread
From: rog @ 2003-07-22 14:09 UTC (permalink / raw)
To: 9fans
> err, what happened to rev(1)?
different thing.
line vs. file
has anyone actually used rev(1) in seriousness before?
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [9fans] text utility
2003-07-22 14:09 ` rog
@ 2003-07-22 14:35 ` boyd, rounin
2003-07-22 16:43 ` rog
2003-07-22 23:28 ` Geoff Collyer
1 sibling, 1 reply; 12+ messages in thread
From: boyd, rounin @ 2003-07-22 14:35 UTC (permalink / raw)
To: 9fans
> different thing.
> line vs. file
i.e., write out lines with reverted order of chars) onto the neXt Archive
i read that as 'reverse the order of the chars on each line'.
http://www.gsp.com/cgi-bin/man.cgi?section=1&topic=rev
The rev utility copies the specified files to the standard output,
reversing the order of characters in every line
> has anyone actually used rev(1) in seriousness before?
yes, iirc, someone at the labs used it to generate a dictionary
for anagrams or crosswords with some:
rev | ... | rev
construction.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [9fans] text utility
2003-07-22 14:09 ` rog
2003-07-22 14:35 ` boyd, rounin
@ 2003-07-22 23:28 ` Geoff Collyer
2003-07-23 15:05 ` rog
2003-07-28 8:47 ` Ralph Corderoy
1 sibling, 2 replies; 12+ messages in thread
From: Geoff Collyer @ 2003-07-22 23:28 UTC (permalink / raw)
To: 9fans
I'm pretty sure it was Doug McIlroy who used
rev <dict | sort >rhymdict
to produce a rhyming dictionary. To find rhyming words, you'd reverse
the suffix of a word, look that up and reverse the result:
look `{echo suffix | rev} rhymdict | rev
This is described in a memo called `Webster's 2nd on the head of a
pin' and dates from the mid-1970s. (I have a copy somewhere.)
As for tac,
tail -1000000000r
does the job for most files of interest (those under a billion lines).
I just tried it on a file of ~250,000 lines; it's quite quick.
Alternatively,
awk '{print NR, $0}' | sort -nr | sed 's/^[0-9]+ //'
does the job more slowly.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [9fans] text utility
2003-07-22 23:28 ` Geoff Collyer
@ 2003-07-23 15:05 ` rog
2003-07-23 18:42 ` Dan Cross
2003-07-28 8:47 ` Ralph Corderoy
1 sibling, 1 reply; 12+ messages in thread
From: rog @ 2003-07-23 15:05 UTC (permalink / raw)
To: 9fans
> As for tac,
>
> tail -1000000000r
interesting... i'd imagined that tac would send all
the *bytes* (or maybe characters) in a file to stdout,
in reverse.
that's three (or four) possible definitions for tac so far.
i wonder how many others there might be.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [9fans] text utility
2003-07-23 15:05 ` rog
@ 2003-07-23 18:42 ` Dan Cross
2003-07-24 9:19 ` matt
0 siblings, 1 reply; 12+ messages in thread
From: Dan Cross @ 2003-07-23 18:42 UTC (permalink / raw)
To: 9fans
Why not use the definition of the tac utility that used to be
distributed with BSD Unix? I think it printed out lines in reverse
order (similar to tail -r). Something to print out all the bytes in a
file in reverse order might be useful, though. Currently, I can't
think why.
- Dan C.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [9fans] text utility
2003-07-23 18:42 ` Dan Cross
@ 2003-07-24 9:19 ` matt
0 siblings, 0 replies; 12+ messages in thread
From: matt @ 2003-07-24 9:19 UTC (permalink / raw)
To: 9fans
Dan Cross wrote:
>Why not use the definition of the tac utility that used to be
>distributed with BSD Unix? I think it printed out lines in reverse
>order (similar to tail -r). Something to print out all the bytes in a
>file in reverse order might be useful, though. Currently, I can't
>think why.
>
> - Dan C.
>
to see what interesting UTF-8 comes out of course
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [9fans] text utility
2003-07-22 23:28 ` Geoff Collyer
2003-07-23 15:05 ` rog
@ 2003-07-28 8:47 ` Ralph Corderoy
2003-07-28 21:58 ` Geoff Collyer
1 sibling, 1 reply; 12+ messages in thread
From: Ralph Corderoy @ 2003-07-28 8:47 UTC (permalink / raw)
To: 9fans
Hi Geoff,
> awk '{print NR, $0}' | sort -nr | sed 's/^[0-9]+ //'
That's what I use, except `cat -n' instead of having awk deal with each
line.
Cheers,
--
Ralph Corderoy. http://inputplus.co.uk/ralph/ http://troff.org/
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [9fans] text utility
2003-07-28 8:47 ` Ralph Corderoy
@ 2003-07-28 21:58 ` Geoff Collyer
2003-07-30 8:25 ` Ralph Corderoy
0 siblings, 1 reply; 12+ messages in thread
From: Geoff Collyer @ 2003-07-28 21:58 UTC (permalink / raw)
To: 9fans
Of course "cat -n" is almost as evil as "cat -v" (-v has a
sublanguage) and doesn't work on Plan 9:
cpu% cat -n
cat: can't open -n: '-n' directory entry not found
One could use "pr -tn" instead of the little awk script, but the
difference in speed really isn't that great. Reading a cached ~2.5MB
file of ~250K lines,
cpu% time awk '{print NR, $0}' test >/dev/null
2.85u 0.13s 3.53r awk {print NR, $0} test
cpu% time pr -tn test >/dev/null
1.75u 0.13s 2.18r pr -tn test
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [9fans] text utility
2003-07-28 21:58 ` Geoff Collyer
@ 2003-07-30 8:25 ` Ralph Corderoy
0 siblings, 0 replies; 12+ messages in thread
From: Ralph Corderoy @ 2003-07-30 8:25 UTC (permalink / raw)
To: 9fans
Hi Geoff,
> One could use "pr -tn" instead of the little awk script, but the
> difference in speed really isn't that great. Reading a cached ~2.5MB
> file of ~250K lines,
>
> cpu% time awk '{print NR, $0}' test >/dev/null
> 2.85u 0.13s 3.53r awk {print NR, $0} test
> cpu% time pr -tn test >/dev/null
> 1.75u 0.13s 2.18r pr -tn test
Fair enough. Under AIX and Linux cat's a win. Using yes(1) so awk's
little work to do:
$ yes y | head -n 250000 | time awk '{print NR, $0}' >/dev/null
real 1.13
user 1.06
sys 0.01
$ yes y | head -n 250000 | time cat -n >/dev/null
real 0.08
user 0.05
sys 0.00
I used it heavily when doing ad-hoc queries on files with millions of
lines. But, like you say, if it's not present, it's no use.
Cheers,
--
Ralph Corderoy. http://inputplus.co.uk/ralph/ http://troff.org/
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2003-07-30 8:25 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-21 11:45 [9fans] text utility pac
2003-07-21 11:52 ` boyd, rounin
2003-07-22 14:09 ` rog
2003-07-22 14:35 ` boyd, rounin
2003-07-22 16:43 ` rog
2003-07-22 23:28 ` Geoff Collyer
2003-07-23 15:05 ` rog
2003-07-23 18:42 ` Dan Cross
2003-07-24 9:19 ` matt
2003-07-28 8:47 ` Ralph Corderoy
2003-07-28 21:58 ` Geoff Collyer
2003-07-30 8:25 ` Ralph Corderoy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).