grep-awk one liner help

Hi guys, I'm trying to create a one line command that does the following.

I will post my command first so you can get the idea better:

ls -larht | awk '{print $4}' | uniq | xargs grep *

__________

ls -larht | awk '{print $4}' | uniq 

This will post the name of the groups of each file inside a folder(without repeating).

Then I need to search those groupnames inside the files using grep.

[erickramirez@sdevgos01 ~/prueba]$ ls -larht
total 12K
-rw-r--r-- 1 erickramirez ccusers   46 Jan 28 08:28 1
-rw-r--r-- 1 erickramirez ccusers   78 Jan 28 08:28 2

[erickramirez@sdevgos01 ~/prueba]$ ls -larht | awk '{print $4}' | uniq

ccusers

## Now I want to search "ccusers" inside each file on the directory

[erickramirez@sdevgos01 ~/prueba]$ ls -larht | awk '{print $4}' | uniq | xargs grep *
grep: ccusers: No such file or directory

It's taking the result of the last command as the second argument (path) instead of the keyword. Please help! :slight_smile:

This perhaps?

ls -larht | awk '{print $4}' | uniq | sed 's/  */|/g' | xargs -I{} grep -E {} *
1 Like

Thanks a lot! really helpfull