Wednesday, April 27, 2022

[SOLVED] grep special filename in all subfolders and put into 1 file

Issue

I have a various folders and many subfolders with random hard names like:

ABC[5DE801E847587AC83684E1C37F7088AE] [2022-03-02T17_03_59.4138983]
ABCD[282F75BB98EC49398DD15F69FBD68E40] [2022-03-02T14_50_27.4273843]

I need to search every folder and subfolder in it and find filenames with names

Pa.txt
pa.txt

And put into one file, one output. How to do that? tried with

find . -wholename '*/pa.txt' -exec cat {} >>out.txt +

But it's skips many folders and subfolders.


Solution

Suggestion 1: find command with composite or filter:

  find . -type f -name "pa.txt" -or -name "Pa.txt"  > out.txt

Suggestion 2: find command using RegExp filter:

  find . -type f -regex "[Pp]a.txt" > out.txt


Answered By - Dudi Boy
Answer Checked By - Terry (WPSolving Volunteer)