1

In a folder and its subfolders, I want to search a pattern. For this I am using: grep+cut+awk+tr pipeline.

printf "I am so        wide alper world zorro the end\t\t\talper\n" > alper.txt
printf "zorro alper alper alper    skfjsdlkfj dslfj dslkj dslfkj sldk\n" > doo.tex
mkdir .git && printf "zorro zoo\n" > .git/test_file.tex
grep -Hrn -e "zorro" --exclude-dir='.git' --color=always -I -F . | \
    cut -c 11- | awk '$0="\033[33;35m"$0' | tr -s '[:space:]' |  ifne less -r

alper.txt:1:I am so wide alper world zorro the end        alper
doo.tex:1:zorro alper alper alper skfjsdlkfj dslfj dslkj dslfkj sldk

Here searched pattern (zorro) shown in bold red color. Is shown with following order:

<filename>:<line_number>:<matching line>

How can I do this pipeline to find the files and awk to search within the files using find?

0

1 Answer 1

2
$ find . \( -name .git -prune \) -o \( -type f -exec \
    awk -v OFS=':' '
        FNR == 1 { fname=FILENAME; sub(/^\.\//,"",fname) }
        /zorro/ { gsub(/ +/," "); gsub(/\t+/,"\t"); print "\033[33;35m" fname, FNR, $0 "\033[0m" }
    ' {} + \)
alper.txt:1:I am so wide alper world zorro the end      alper
doo.tex:1:zorro alper alper alper skfjsdlkfj dslfj dslkj dslfkj sldk

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.