inplace editing - How to use Ruby's command line in-place-edit mode to remove lines from a text file -
i've been long time perl user, , in perl can remove lines text files this:
perl -pi -e 'undef $_ if m/some-condition/' file.txt
i'm trying move scripting ruby, in-place-edit, wrote this:
ruby -pi -e '$_ = nil if $_ =~ /some-condition/' file.text
but instead nullified entire file. tried
ruby -pi -e 'nil if $_ =~ /some-condition/' file.text
but didn't anything.
any ideas?
ruby -pi -e '$_ = nil if $_ =~ /some-condition/' file.text
should correct. if doesn't work, problem in some-condition
. demonstrate,
echo -e "a\nb\nc" > x ; ruby -pi -e '$_ = nil if $_ =~ /b/' x ; cat x
prints
a c
Comments
Post a Comment