Stream Editing

1 · Jan Lelis · May 17, 2015, midnight
One of Ruby's goals was to replace popular unix stream editors like awk or sed, which both have the concept of manipulating files in a line-based manner. Ruby has the -n option for this: Causes Ruby to assume the following loop around your script, which makes it iterate over file name arguments somewhat like sed -n or awk. while gets ... end And its sibling -p: Acts mostly same as -n switch, but print the value of variable $_ at the each end of the loop. For example: ...