[บันทึกกันลืม] วิธีหาไฟล์ที่มีคำที่ต้องการ โดยแสดงเฉพาะ ชื่อไฟล์เท่านั้น

โจทย์ ต้องการหาไฟล์ที่มีคำว่า text_pattern จากทุกไฟล์ในไดเรคทอรี่ /path/to/ ที่มีนามสกุล .ipynb แต่ต้องไม่มีคำว่า checkpoint ใน path หรือชื่อไฟล์

find /path/to -name "*.ipynb" ! -name "*checkpoint*" -type f -print0 | while read -r -d '' i; do
    if grep -q "text_pattern" "$i"; then
         echo "$i"  # Output only the filename if the pattern is found
    fi;
done
Share the Post:

Related Posts

PSU One Passport (Authentik)

Post Views: 91 คลิก “ลงชื่อเข้าใช้ด้วย PSU PASSPORT” จะได้หน้าดังภาพ เมื่อได้หน้านี้มี 2 ทางเลือกคือ

Read More