help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Printing in red during output from head


From: Alex fxmbsw7 Ratchev
Subject: Re: Printing in red during output from head
Date: Wed, 21 Jul 2021 13:43:49 +0200

to be run with -v ml="$n" and with files as arguments

#!/usr/bin/gawk -f

BEGIN {
 ORS = ""
 RS = "<==($|\n)|=|(^|\n)==>|\n"
}

RT ~ ">" {
 if ( RT ~ /^\n/ ) { sub( /./, "", RT ) ; n = "\n" }
 $0 = $0 ( ( n != "" ) ? n : "" ) "\33[31m" RT
}

RT ~ "<" {
 if ( RT ~ "\n$" ) { sub( ".$", "", RT ) ; n = "\n" }
 $0 = $0 RT "\33[m" ( ( n != "" ) ? n : "" )
}

RT == "\n" {
 $0 = $0 RT
}

{
 print
 # print FILENAME " " ; print
 n = ""
 if ( ml && FNR > ml ) nextfile
}

On Wed, Jul 21, 2021 at 1:29 PM Alex fxmbsw7 Ratchev <fxmbsw7@gmail.com> wrote:
>
> #!/usr/bin/gawk -f
>
> BEGIN {
>  ORS = ""
>  RS = "<==($|\n)|=|(^|\n)==>"
> }
>
> RT ~ ">" {
>  if ( RT ~ /^\n/ ) { sub( /./, "", RT ) ; n = "\n" }
>  $0 = $0 ( ( n != "" ) ? n : "" ) "\33[31m" RT
> }
>
> RT ~ "<" {
>  if ( RT ~ "\n$" ) { sub( ".$", "", RT ) ; n = "\n" }
>  $0 = $0 RT "\33[m" ( ( n != "" ) ? n : "" )
> }
>
> {
>  print
>  n = ""
> }
>
>
> -- end of gawk script ---
>
>
> then you just gawk -f file.gawk or chmod +x file and file or ./file it
> in the pipe say
> also with one two lines a n = 5 max for example can be implented, to
> skip head for direct only gawk=
>
> On Wed, Jul 21, 2021 at 1:03 PM <lisa-asket@perso.be> wrote:
> >
> >
> > I would like to have the whole line in red including the arrow tags.
> >
> > From: Alex fxmbsw7 Ratchev <fxmbsw7@gmail.com>
> > To: lisa-asket@perso.be
> > Subject: Re: Printing in red during output from head
> > Date: 21/07/2021 12:51:44 Europe/Paris
> > Cc: help-bash <help-bash@gnu.org>
> >
> > the <<< redirects its next argument to stdin of the cmd in question
> > it just was a copypaste of my terminal, where i tested, .. didnt remove it
> > in the end no '<<< "str..."'
> >
> > On Wed, Jul 21, 2021 at 12:50 PM <lisa-asket@perso.be> wrote:
> > >
> > > I am getting confused about foo and bar.
> > >
> > >
> > > From: Alex fxmbsw7 Ratchev <fxmbsw7@gmail.com>
> > > To: lisa-asket@perso.be
> > > Subject: Re: Printing in red during output from head
> > > Date: 21/07/2021 05:28:19 Europe/Paris
> > > Cc: help-bash <help-bash@gnu.org>
> > >
> > > gawk -v ORS= -v RS='<==|==>' 'RT == "==>" { $0 = $0 RT "\33[31m" } RT
> > > == "<==" { $0 = $0 "\33[m" RT } 1' <<<'==> foo bar <=='$'\nbarbar\n==>
> > > again <==\nbla'
> > >
> > > find | .. | gawk
> > > gawk <( find .. )
> > >
> >



reply via email to

[Prev in Thread] Current Thread [Next in Thread]