The input file has the following lines and segregate these using the 2nd field '+' symbol lines in one file and '-' symbol lines in another file:
24 + I am the Five man
22 - Who are you? The new number two!
51 + . . . And four on the floor
42 +
16 - Who is number one?
33 - I three you.
is it possible when the $2 is '+', a=$1+500 and b=$1-500 at the same time when the $2 is '-', a=$1-500 and b=$1+500? 'a' and 'b' are the new variables.
Another option
awk 'BEGIN{m["+"]="plus.txt";m["-"]="minus.txt"} $2 ~ /^[+-]$/{print>>m[$2]}'
With Perl:
perl -lne '/^\d+ -/ && print(STDERR) || print' input 2> minus > plus
in a slightly different form:
perl -lpe 'select(/^\d+ -/?STDERR:STDOUT)' input 2> minus > plus
Also possible using tee
:
tee >(sed -n '/^[0-9]* -/p' > minus) < input | \
sed -n '/^[0-9]* +/p' > plus
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With