1

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

  • May be sed helps? Can you somehow indentify lines which you want to delete? By number, key-phrase, etc. ? – Costas Dec 26 '14 at 11:33
  • @Costas yes, there will be one unique account number in file and i can find the line number for the same which i need to delete – Aravind Dec 26 '14 at 12:10
  • So there is not a problem to use sed for your task sed --in-place 'line_number_from,line_number_till d' file – Costas Dec 26 '14 at 12:17
  • 1
    Why can't it be opened in vi? – Erathiel Sep 9 '15 at 9:13
  • 1
    What is less mode? Is that a vi feature? – Raphael Ahrens Sep 9 '15 at 9:15
1

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.

-2

Yes it is possible

  1. Open the file in less.
  2. Type vi. The file will open in vi.
  3. Press Esc [number_of_lines] dd, then save the file (type :wq to write and quit).
  4. It will go back to less with modified content.
  5. Exit
  • 1
    I'm not sure this will work as the OP stated that 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.