0

I want to perform operations on the files found by the find command which already has a -exec option.

find . -type f -exec zgrep -li "4168781103" {} +

Output:

./results/Query_20200501_18_32_00_msisdn_14168781103_detail.csv
./results/Query_20200501_18_32_02_msisdn_14168781103_summary.csv
./results/Query_20200501_18_32_02_msisdn_14168781103_detail.csv
./results/Query_20200501_18_32_04_msisdn_14168781103_summary.csv
./results/Query_20200501_18_32_04_msisdn_14168781103_detail.csv
./results/Query_20200501_18_32_51_msisdn_14168781103_summary.csv
./results/Query_20200501_18_32_51_msisdn_14168781103_detail.csv
./results/Query_20200501_18_36_03_msisdn_14168781103_summary.csv
./2311/2020_05/01/18/2311.TRL_20200501180400114.c.5.3.38.0.trl.gz
./2311/2020_05/01/18/trlindex.db
./2311/2020_05/01/18/2311.TRL_20200501180500115.c.5.3.38.0.trl.gz
./2311/2020_05/01/18/2311.TRL_20200501180600116.c.5.3.38.0.trl.gz
./2311/2020_05/01/18/2311.TRL_20200501180700117.c.5.3.38.0.trl.gz
./2311/2020_05/01/18/2311.TRL_20200501181000118.c.5.3.38.0.trl.gz
./2311/2020_05/01/18/2311.TRL_20200501183000119.c.5.3.38.0.trl.gz
./2311/2020_05/01/18/2311.TRL_20200501183100120.c.5.3.38.0.trl.gz
./2311/2020_05/01/18/2311.TRL_20200501183200121.c.5.3.38.0.trl.gz
./2323/2020_05/01/18/2323.TRL_20200501180400296.4.3.18.0.trl.gz

I found these files containing the key string 4168781103 using find with -exec option, Now i want to print the contents of all the files found below ending with file name .trl.gz only or run a search on these files....

Cyrus
  • 5,751

1 Answers1

1

If you want to process only the .trl.gz files in the end, you can focus find on them in the first place :

find . -type f -name "*.trl.gz" -exec zgrep -li "4168781103" {} +

Then for further processing, you can pipe through xargs.

Printing :

find . -type f **-name "*.trl.gz"** -exec zgrep -li "4168781103" {} + **| xargs cat ...**

Further search :

find . -type f **-name "*.trl.gz"** -exec zgrep -li "4168781103" {} + **| xargs zgrep ...**

Or use command substitution in your POSIX-compliant shell:

cat $(find . -type f -name "*.trl.gz" -exec zgrep -li "4168781103" {} +)
Hoel
  • 26