I have a file (huge size) which cannot be opened in vi
but in less
mode and I want to delete the lines which I do not required. But I am unable to delete lines from file open in less
mode.
Please suggest how can I delete lines in less
mode
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityI have a file (huge size) which cannot be opened in vi
but in less
mode and I want to delete the lines which I do not required. But I am unable to delete lines from file open in less
mode.
Please suggest how can I delete lines in less
mode
Probably the easiest thing would be to use sed
.
sed '/pattern/d' file
to delete lines containing a certain pattern.
sed 'start_line_number,end_line_number d' file
to delete a range of lines.
Both examples above will just print the file contents to STDOUT without modifying the contents. If you want to modify the actual file add -i
or --in-place
immediately after sed
.
Yes it is possible
vi
. The file will open in vi.Esc [number_of_lines] dd
, then save the file (type :wq
to write and quit).less
with modified content.vi
can't be used and we don't know why.
– Erathiel
Sep 9 '15 at 9:13
v
invokes ${EDITOR:-vi} and, as has been pointed out, that is explicitly ruled out.
– jasonwryan
Sep 9 '15 at 9:24
sed
helps? Can you somehow indentify lines which you want to delete? By number, key-phrase, etc. ? – Costas Dec 26 '14 at 11:33sed
for your tasksed --in-place 'line_number_from,line_number_till d' file
– Costas Dec 26 '14 at 12:17