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 12:31:57 +0200

i posted this gawk cause awk is normal in unix text processing, and
bash is slow there
theres for me two trees, one is cmds like bash, the other text or data
done by like pipes

i can later when done post a bash only solution
..which is: just mod it to your find args + -print0

#!/bin/bash

: ${n:=3}

mapfile -t -d '' F < <( find "${@:-.}" -type f -maxdepth 1 -print0 )
for f in "${F[@]}" ; do
 i= res=
 while (( ++i <= $n )) ; do
  read -r r
  [[ $r =~ '==> '(.*)' <==' ]] &&
   res+=$'==> \e[31m'"${BASH_REMATCH[1]}"$'\e[m <==\n' ||
   res+=$r$'\n'
 done <"$f"
 printf %s\\n "$res"
done

On Wed, Jul 21, 2021 at 5:38 AM Alex fxmbsw7 Ratchev <fxmbsw7@gmail.com> wrote:
>
> mapfile -d '' -t files < <( find .. -print0 )
> gawk '..' <( head .. "${files[@]}" )
>
> On Wed, Jul 21, 2021 at 5:33 AM Alex fxmbsw7 Ratchev <fxmbsw7@gmail.com> 
> wrote:
> >
> > that find | .. | gawk without the <<< - was just for testing here
> >
> > On Wed, Jul 21, 2021 at 5:28 AM Alex fxmbsw7 Ratchev <fxmbsw7@gmail.com> 
> > wrote:
> > >
> > > 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 .. )
> > >
> > > On Wed, Jul 21, 2021 at 3:17 AM <lisa-asket@perso.be> wrote:
> > > >
> > > >
> > > >
> > > > I am using the following command to output the first n lines of matched 
> > > > files.
> > > >
> > > >
> > > >
> > > > find "$fdir" \( -name \*.org -o -name \*.texi \)  | xargs head -n "$n"
> > > >
> > > >
> > > >
> > > > For one file I get
> > > >
> > > >
> > > >
> > > > ==> ./01cuneus/igtdr108/igtdr108.texi <==
> > > > \input texinfo
> > > > @set tlpage-tdr108
> > > > @set fmatr-tdr108
> > > >
> > > > @c %**start of header
> > > > @setfilename Notation.info
> > > > @settitle Notation
> > > > @smallbook
> > > > @finalout
> > > > @c %**end of header
> > > >
> > > > @c Org Mode Commands
> > > > @ignore
> > > >
> > > >
> > > > How can I get the file name (enclosed within ==> and <==) to be 
> > > > coloured red
> > > >
> > > > in the command line terminal.
> > > >
> > > >
> > > >
> > > >



reply via email to

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