deleting a line from a text file

This is a discussion on deleting a line from a text file within the Tech Board forums, part of the Community Boards category; If I am on linux , I use the " grep -v " command to list all the lines that ...

  1. #1
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342

    deleting a line from a text file

    If I am on linux , I use the " grep -v " command to list all the lines that do not contain the pattern and then I direct the output that I am getting to the same file to overwrite it.
    something like ,
    Code:
      grep  -v "$pat" $file > $file
    How can I do this on a windows system?

    PS: sorry , I should have posted this in the windows board
    In the middle of difficulty, lies opportunity

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    I'd be surprised if that even works on unix, given that the shell is going to open the output file before grep gets a chance to read it.

    As for grep on windows, then I'd suggest
    http://unxutils.sourceforge.net/
    or
    http://www.cygwin.com/
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342
    >I'd be surprised if that even works on unix
    I have used it a couple of times and it has worked. I think i was on bash shell on both the times. will check up anyway. and thanks for those two links
    In the middle of difficulty, lies opportunity

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  2. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  3. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  4. Position FILE pointer to a specified line of Text file
    By jessica_xie in forum C Programming
    Replies: 2
    Last Post: 02-04-2005, 02:52 PM
  5. Outputting String arrays in windows
    By Xterria in forum Game Programming
    Replies: 11
    Last Post: 11-13-2001, 06:35 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21