Re: tac replacement





On 11/26/2007 3:16 PM, Jürgen Kahrs wrote:
yiyu.jgl@xxxxxxxxx schrieb:


I need to process the end of a file before the beginning. I have seen
some threads where a tac | awk ... | tac solution is proposed, but
there is always the problem of not having tac in your system.


If you have a Unix sort command, then try this:

awk '{print NR, $0}' data_file.txt | sort -n -r | awk '{$1=""; print $0}'

That'll add a leading space and compress the rest of the spacing between fields.
If you really wanted to do that in awk|sort|awk, you'd do:

awk '{print NR, $0}' data_file.txt | sort -n -r | awk 'sub(/[[:digit:]]+ /,"")'

There are of course better UNIX tac-alternatives but that'd be best discussed in
comp.unix.shell....

Ed.

.



Relevant Pages

  • tac replacement
    ... some threads where a tac | awk ... ... gentoo forum, but didn't take note of the url). ...
    (comp.lang.awk)
  • Re: tac replacement
    ... yiyu.jgl@xxxxxxxxx schrieb: ... some threads where a tac | awk ... ...
    (comp.lang.awk)
  • Re: tac (reverse of cat) as pure executable for HP-UX 10.20
    ... instead of "no tac". ... list of different ways to do a reverse cat that I compiled years ago. ... # Most implementations of awk can handle bigger files than sed. ... # Just be aware that most seds will choke on big files using the ...
    (comp.sys.hp.hpux)
  • Re: Sed: How to join lines back
    ... >I have a very large log file with lots of different sorts of lines in ... I'd use tac to reverse the file, then use awk to join the lines, ...
    (comp.unix.shell)
  • Re: Sed: How to join lines back
    ... >I have a very large log file with lots of different sorts of lines in ... I'd use tac to reverse the file, then use awk to join the lines, ...
    (comp.unix.questions)