8/19 Shell script gurus please help. I need to strip the first 10 lines
and the last 3 lines off a whole bunch of files. Is there an easy
way to use sed to do this? Thanks.
\_ Sounds like a trivial job for head and tail.
\_ It is: cat foo | tail -n +10 | tail -r | tail +4 | tail -r
\_ Not completely trivial. You'd need a wc in there somewhere.
head needs a +<number> functionality.
\_ Suppose you also have GNU tac:
head +10 | tac | head +3 | tac
\_ Why the wc? head -n 10, tail -3? --dim
should work. -- schoen
\_ perl.
\-there is a fairly evil way to do it in sed [first 10 lines
is easy] last 3 is somewhat evil. not a good idea to do in sed unless
like at least a 3rd level sed user. if you explain better what you
\_ I still need 23 exp to make 3rd level.
want i can probably five you the incantation ... do you want to SEE
the first 10 and last 3 or do you want to delete them and write the
file back with the first 10 gone and the bottom 3 gone. also, if you
are operating on a bunch of files, the sed line count will continue
across files ... so you have to operate on them one at a time.
using tac is even more begging the question than saying "ues perl".
using head/tail is cheeseball, just like "cut" is cheeseball [i use
cut a lot but i at least know it is cheeseball.]. this is actually
probably something you want to do inperl because writing the "error
checks" [what if it is a 5 line file] is simpler in pl. --psb, 18th
level sed mage.
\_ sed, yucky. awk, yucky. perl, good.
\-Don't be too proud of this
technological terror you've compiled. The abilities of perl are
insignificant next to the power of Emacs. --parth vader
deathstar.lbl.gov. 43200 A 131.243.164.67
\_ Oh yeah? Let's see you grab the first 10 and last 3 lines
of a list of files in emacs from the command line.
\_ I need the files without the first 10 lines and the
last 3 lines. BTW, "head +3" doesn't work. head does
NOT take "+" parameters. Thanks a lot mighty psb.
\_ perl. |