Forum Home
Press F1
 
Thread ID: 89672 2008-05-08 03:36:00 Regular expressions need to echo out all lines not beginning with hash Morgenmuffel (187) Press F1
Post ID Timestamp Content User
667214 2008-05-08 03:36:00 Hi

All i have a 500 line file

and i need to echo out all the lines that don't begin with #
note sometimes there is a space or a tab before the hash

eg
source.txt


womble wimblw
# poddle paddle
# Zip Zap
nongle wongle


destination.txt


womble wimblw
nongle wongle


I did have a batch file that did this, unfortunately sometime in the recent past i have overwritten it with gibberish (and backed the blasted gibberish up as well)

Unfortunatly the below is as far as i have got, and it is completely wrong

grep !'^ *#' c:\source.txt > destination.txt

I know I've screwed the code completely, also I'm not sure it runs on windows which could be a problem, i know my bat file ran perfectly just can't remember for the life of me what the hell i did to get this to work

I'm just so narked that i overwrote my backup
Morgenmuffel (187)
667215 2008-05-08 04:10:00 grep -v "^.*#" c:\source.txt > destination.txt robsonde (120)
667216 2008-05-08 09:06:00 Cheers Rob I'll try that out tomorrow, I was vaguely close,

I really wish they taught regular expressions in the programming type classes i took as they save a heck of a lot of time, but i am really struggling with learning them outside the class environment
Morgenmuffel (187)
1