How can I do it. 
Author Message
 How can I do it.

Is there a way to say print everything except the last line of a file.

Thanks for your help.

-Alex



Wed, 23 Feb 2000 03:00:00 GMT  
 How can I do it.


Quote:

>Is there a way to say print everything except the last line of a file.

{if (FNR>1) {print old}; old=$0}

--
"His name is Henry, a proof how unequally the gifts of fortune are bestowed."
-Jane Austen, 10/14/1813 || Henry Churchyard http://uts.cc.utexas.edu/~churchh



Wed, 23 Feb 2000 03:00:00 GMT  
 How can I do it.

Quote:

> Is there a way to say print everything except the last line of a file.

> Thanks for your help.

> -Alex

More generally you can drop the last n lines as follows.
Example for n=3:

awk 'FNR>n {print buf[k]} {buf[k]=$0; k++; if (k==n) k=0}' k=0 n=3

Note:
  n must be greater than 0.
  k must be initialized. Otherwise you loose the first line.
  (or write buf[k+0] instead)
--
Torsten Sillke



Wed, 23 Feb 2000 03:00:00 GMT  
 How can I do it.



Quote:
>Is there a way to say print everything except the last line of a file.

>Thanks for your help.

>-Alex

Most concise with sed:

sed '$d'
--
Adam Lovick



Thu, 24 Feb 2000 03:00:00 GMT  
 How can I do it.

for seders, sed has replaced many utilies, e.g.
cut, head, tail, awk, perl, & the mighty
emacs (orders of mag smaller/faster).
sed15 (dos) = 22k

to print every line except the nth :
sed 1d
sed 2d
sed $d

to print every line except the nth to the mth (inclusively)
sed "1,4d"
sed "2,111d"
sed "111,$d"

to delete all consecutive empty lines except 1
sed "/./,/^$/!d"

to replace the 4th incident of substring with nothing
sed "s/substring//4"

to truncate lines after the 72nd char
sed "s/.\{72,\}//"

to fold lines after the ....
...

-------------------------------------------------------------
right now
seders has a contest
print the first line of every para

will be followed by
print the last line of every para

a sed stud has reengineered unix dc (calculator) in sed
much slower
less bugs

join seders
email me.



: >Is there a way to say print everything except the last line of a file.
: >
: >Thanks for your help.
: >
: >-Alex

: Most concise with sed:

: sed '$d'
: --
: Adam Lovick

--
=-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
al aab, seders moderator                                      sed u soon
               it is not zat we do not see the  s o l u t i o n          
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+



Mon, 28 Feb 2000 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. CA Cans VO ?

2. It's not bad canned meat...

3. It's not bad canned meat...

4. It's not bad canned meat...

5. Using CGI module with 'canned queries'

6. It's not bad canned meat...

7. Doing assembly and really doing assembly

8. Doing assembly and really doing assembly

9. What can be done in FORTRAN that cannot be done in C/C++?

10. How can view styles be done?

11. - Fall 2003 Release done

12. How to minimize damage done by Java

 

 
Powered by phpBB® Forum Software