there are zillion way to do it, first two I came with are awk and grep (in that order)
awk
awk '/debug/ { print > "debug.txt" ; next ;} { print } ' logfile > info.txt
where
/debug
/ select line with word debug
{ print > "debug.txt" ;
print to debug.txt
next ;}
read next line in logfile
{ print }
if no debug, print to stdout
> info.txt
redirect stdout to info.txt
a more formal command
awk '/debug/ { print > "debug.txt" ; }
$0 !~ /debug/ { print > "info.txt " ; } ' logfile
where
$0 !~ /debug/
means, if debug does not appear on the line.
grep
grep debug logfile > debug.txt
grep -v debug logfile > info.txt
where
grep debug
select line with debug
grep -v debug
select line without debug
- logfile is read twice
please note also that previous content of debug.txt and info.txt will be deleted by using >
to keep it, use >>
in shell or in awk.
read
command reads its input data byte by byte. For further info, please see Why is using a shell loop to process text considered bad practice?, and the associated links. I was going to post an answer containing a short script using grep, and also mentioning that you can easily do it using awk, but Archemar has beaten me to it. :) – PM 2Ring Jul 07 '15 at 03:56