Multiple Commands in PS

I need to find in file where the record starts with "A,U,I,R" and their file name

Record will look like below

A|1|138||XXXX|XX|XX
U|2|XX|XX|XX|XX
R|3|EK|XX|XX|XX
D|4|TY|CC|CC|CC
find ./*.dat -exec egrep "^A|U|I|R" \; -exec cut -d'|' -f1,2 \; -exec sort -u {} /dev/null \;

But it does not return any values.

The different -exec primaries are not piped into each other.

You can either pipe find into cut and sort or use a single -exec and have it run a simple shell script.

Regards,
Alister

i put your data in fileA.dat:

$ find . -name '*.dat' -exec sh -c 'grep -He "^[AUIR]" "$@" | cut -d"|" -f1,2 | sort -u' _ {} +
./fileA.dat:A|1
./fileA.dat:R|3
./fileA.dat:U|2

You probably only need find if you're recursively searching subdirectories.

$ grep -e "^[AUIR]" *.dat | cut -d"|" -f1,2 | sort -u
fileA.dat:A|1
fileA.dat:R|3
fileA.dat:U|2
fileB.dat:A|1
fileB.dat:R|3
fileB.dat:U|2
1 Like

Great!!!

Could you please explain this part

'grep -He "^[AUIR]" "$@" 

and need of this

_ {} +