1

I want to shorten a log file on a unix system with very limited shell capability. My preferred way to do this would be with ed.

Deleting a fix number of lines works fine:

ed -s file.txt <<< $'1,4d\nwq'

But how can I expand the number of lines to delete from a shell variable in a ed oneliner? I'm looking for something like:

n_del=4; ed -s file.txt <<< $'1,\${n_del}d\nwq'
StackUnderflow
  • 159
  • 1
  • 7

1 Answers1

3

Although it’s perfectly normal in shell to just concatenate strings quoted in different ways and even non-quoted, so it may looks like:

$ n_del=4; ed -s test <<< "1,${n_del}"d$'\n'wq

I believe, here-doc would be more cleaner here, than one-liner:

$ n_del=4
$ ed -s test <<_EOF
1,${n_del}d
wq
_EOF
Dmitry Alexandrov
  • 1,693
  • 12
  • 14
  • 1
    `ed` used to have limits on the size of files that it can process. Maybe thats fixed now. If a problem, the O.P. may want to switch to using `ex` instead. Good luck to all. – shellter Sep 09 '14 at 11:18