[RndTbl] Easy script question?

Kevin McGregor kevin.a.mcgregor at gmail.com
Wed Mar 4 20:12:24 CST 2015


Duh -- forgot to mention it's for Solaris 11.2. head on Solaris is not GNU.
OTOH, it has 'tac'! So I guess I'll use that with tail +n (or something
like that).

Thanks, guys!

On Wed, Mar 4, 2015 at 4:19 PM, Gilbert E. Detillieux <
gedetil at cs.umanitoba.ca> wrote:

> Sometimes, it's the simple solutions that elude us...  :)
>
> But wait!  Compatibility alert!  Using a negative line count on head(1) is
> a GNU extension, and likely won't work with more "traditional" UNIX
> implementations.
>
> Gilbert
>
> On 04/03/2015 4:10 PM, John Lange wrote:
>
>> man head
>>
>> head --lines=-5 textfile.txt
>>
>> all but the last 5 lines.
>>
>>
>> On Wed, Mar 4, 2015 at 3:49 PM, Robert Keizer <robert at keizer.ca
>> <mailto:robert at keizer.ca>> wrote:
>>
>>     Idea from thread below:
>>
>>     | awk '{if(a) print a;a=b;b=$0}'
>>
>>     Note that you might want to include a little more logic if you want
>>     blanklines in there..  This doesn't store all of it in a file or in
>> ram.
>>
>>
>>     http://askubuntu.com/questions/475694/awk-command-
>> to-print-all-the-lines-except-the-last-three-lines
>>
>>     On 2015-03-04 3:33 PM, Adam Thompson wrote:
>>     > Like Tim said, you first have to know how many lines exist in the
>> file
>>     > before you can do anything other than stream processing.
>>     > On moderately-sized inputs, "wc -l" works reasonably well. On large
>>     > inputs, there's no way to do this efficiently unless you're willing
>> to
>>     > sacrifice accuracy.
>>     >
>>     > F=filename
>>     > L=$(wc -l $F)
>>     > head -n $(( $L - num_of_ignored_lines ))
>>     >
>>     > -Adam
>>     >
>>     > On March 4, 2015 2:36:24 PM CST, Kevin McGregor
>>     > <kevin.a.mcgregor at gmail.com <mailto:kevin.a.mcgregor at gmail.com>>
>> wrote:
>>     >
>>     >     Can someone help me out? I'm too tired to think straight.
>>     >
>>     >     Is there an easy/short way to get all BUT the last n lines of a
>>     >     text file/input? All I can think of is reversing the input line
>>     >     order and tail +n or something like that. FYI the input is not
>>     >     very big.
>>     >
>>     >     Kevin
>>
>
> --
> Gilbert E. Detillieux           E-mail: <gedetil at muug.mb.ca>
> Manitoba UNIX User Group        Web:    http://www.muug.mb.ca/
> PO Box 130 St-Boniface          Phone:  (204)474-8161
> Winnipeg MB CANADA  R2H 3B4     Fax:    (204)474-7609
>
> _______________________________________________
> Roundtable mailing list
> Roundtable at muug.mb.ca
> http://www.muug.mb.ca/mailman/listinfo/roundtable
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.muug.mb.ca/pipermail/roundtable/attachments/20150304/bd4e9f08/attachment.html>


More information about the Roundtable mailing list