11/16 "sed '/^[0-9].*$/\!d' inputfile" will print out only the lines
of a file that start with numbers. Supposed I want to print out
the 1st, 6th, 10th, 16th, etc lines that begin with a number.
How can I do that elegantly with sed or perl or whatever?
\_ perl -ne 'print if /^\d/ && $count++ % 5 == 0' --mconst
\_ You can replace all the newlines with a new record separator (eg
"FOO") and then awk '{print $1, $6, $10, $16}'.
\- to do this either you need to understand a little bit about
how sed works and then write a little sed program OR if
you want a cryptic one liner, it heavily depends on the
version of sed ... i cant think of a simple way to do
this in "genreic sed" ... i assume your list doenst end
at 16 ... that is trivial. i think gsed supports the +5d
operator. --psb
\_ perl -ne 'print if /^\d/ && <compare $. as line #>' file
the compare could be e.g.: $. =~ /^(1|6|10|16)$/
--dbushong
\- if all you want to do is print out those 4 lines it is
' trivial ... sed -n -e '1p;6p;10p;16p' --psb
\_ This has to work for a file that is 100000 lines long. That's
what I meant by etc. I would have thought there would be an
elegent way to basically tell it to print the first line,
skip the next n lines, print the next line, skip the next n
lines, etc. -op
\_ Is n 5, 4, or 6? |