Re: [ILUG] Removing Txt file lines using Linux Scripts

From: 'Lars Hecking' (lhecking at domain nmrc.ucc.ie)
Date: Fri 31 Mar 2000 - 16:16:51 IST


Burke, Gary : GIG IS&T writes:
> ]> Can any one tell me , how to remove some 5-6 lines
> ]> from a big text file using linux scripts
> ]
> ] ed vi sed tail head awk perl python grep. And I'm sure I missed
> ] another dozen.
>
> I can think of a few not very nice ways that may work, but I'm sure there
> are better ways.
>
> Firstly, if you know the exact text of the lines you want to remove, then
> try something like
>
> cat filename | grep -v "first line" | grep -v "second line" | .... | grep -v
> "last line" > newfilename
 
 Argh. Useless use of cat.

 egrep -v "first line|second line|..." filename >newfilename

> But that's horrible. Another way would be to use vi or emacs. If you know
> which lines they will be all the time, then you can store the keystrokes you
> requires in a file. I know using Emacs you can use ^Q and a character (like
> ^X) and it will put a ^X into the buffer instead of Email trying to
> understand it. I'm sure this is possible in vim. So, you would have a file
> like...
>
> ^N^N^N^N^N^K^K^K^K^K^K^X^S^X^C
>
> and use a command line
>
> emacs filename < keystrokesfile
 
 There is sucha thing as ed scripts ...

> Though that is also very very messy.
>
> There are probably much better ways, and I'm sure someone will come up with
> a few better ones for you.
 
 It really depends on what exactly he wants to do, and what the input looks
 like.



This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:05:46 GMT