Tag Info

New answers tagged

1

I also throw perl at everything but will sometimes add sed for flavor: $ sed 's/^\w/\n&/' file | perl -000ne 'print if /apollo/' com.apollo.apollonetworkcheck 1026ms running, 88 wakeups 88 alarms: flg=0x14 The sed will add an extra newline between each record. It simply looks for lines that begin with an alphanumeric character (^\w) and the ...


2

Your idea to use a regex record separator is elegant, but remember that awk will consume the corresponding text, which in your case will be the first non-whitespace character of the following record. If your system has the GNU version of awk, you can access the most recently matched RS via the RT variable, however you would still need to save the result in ...


1

with a awk and a parameter (file filter.awk) BEGIN { p=0 ; } # no printing { if ( (substr($0,1,1) != " ") && (substr($0,1,1) != "\t" ) ) p=0 ; # if no blank stop printing if ( index($0,name) > 1 ) p=1 ; # pattern found ? if (p) print ; } $0 is the entire line substr($0,1,1) is first caracter of line and the result awk -v name=apollo ...


2

I always throw perl at everything :-) perl -ne 'if (/^\s/) { $x.=$_ }else{print $x if $x=~/apollo/; $x=$_} END {print $x if $x=~/apollo/}' file.txt Edit: explanation of the one-liner: -n implies a loop over the input, not printing by default at the end of each loop (-p is the same but does print the line by default). -e specifies an expression, or code ...



Top 50 recent answers are included