Reputation: 495
When using ruby -pi.xxx -e '$stdout.print $_' ./some_file.txt
ruby is going to write into the file some_file.txt
and I will end up having every text line twice in my file.
How can I redirect the input to end up in the console and not in my file?
Upvotes: 1
Views: 249
Reputation: 54684
From the Ruby man page:
-i extension
Specifies in-place-edit mode. The extension, if specified, is added to old file name
to make a backup copy.
In-place edit mode means that the output of the program is written to the original file instead of $stdout. To change this back to printing to stdout, simply leave out the -i
flag, i.e.
ruby -pe '$stdout.print $_' ./some_file.txt
Some side notes:
$stdout.print $_
does exactly the same as print $_
ruby -ne 'puts $_ * 2' ./some_file.txt
or ruby -pe '$_ *= 2' ./some_file.txt
although I think the first one is clearer.Upvotes: 1