W_James
(W. James)
1
I have a file of code that has "!"-delimited lines and other non !-delimited
lines. I want to remove all the "!"-delimited lines
!some stuff that i do not want!
lots of other stuff that i want
lots of other stuff that i want
!some stuff that i do not want!
lots of other stuff that i want
lots of other stuff that i want
What would be a simple ruby script to use regex and remove all the
!....!
lines?
Thanks!
awk "!/!/" myfile >newfile
ruby -pne "next if /!/" myfile >newfile
Oops, spoke too soon. The file seems to have just '\r' at the end
of each line (Unix vs. Windows?).
IO.readlines(myfile)[0] gives
#=>"good stuff\r!badstuff!\rMore good stuff\r!More bad stuff!\r"
ruby -pne "BEGIN{$/=13.chr}; next if /!/" myfile >newfile
awk "!/!/" RS="\r" myfile >newfile
···
On Jan 12, 7:37 pm, "itsme213" <itsme...@hotmail.com> wrote:
The trick here is setting $/ to the value you want. For more
information, see:
http://phrogz.net/ProgrammingRuby/language.html#inputoutputvariables
···
On Jan 13, 1:12 am, William James <w_a_x_...@yahoo.com> wrote:
On Jan 12, 7:37 pm, "itsme213" <itsme...@hotmail.com> wrote:
> I have a file of code that has "!"-delimited lines and other non !-delimited
> lines. I want to remove all the "!"-delimited lines
> !some stuff that i do not want!
> lots of other stuff that i want
> lots of other stuff that i want
> !some stuff that i do not want!
> lots of other stuff that i want
> lots of other stuff that i want
> What would be a simple ruby script to use regex and remove all the
> !....!
> lines?
> Thanks!
awk "!/!/" myfile >newfile
ruby -pne "next if /!/" myfile >newfile
> Oops, spoke too soon. The file seems to have just '\r' at the end
> of each line (Unix vs. Windows?).
> IO.readlines(myfile)[0] gives
> #=>"good stuff\r!badstuff!\rMore good stuff\r!More bad stuff!\r"
ruby -pne "BEGIN{$/=13.chr}; next if /!/" myfile >newfile