0026 | ค้นหา และแก้ไขแฟ้มบน linux แบบโคตรง่าย

Monday, July 21st, 2008 Posted in Linux | 3 Comments »

เอามาเก็บไว้ เพิ่งแก้เครื่องเสร็จไปเครื่องนึง (มีแววได้ใช้อีกเร็วๆ นี้)

ก่อนอื่นเลย คำสั่งค้นหา (ขอบคุณพี่วุธ ผ่านพี่โดม thaicybergames ด้วยครับ)

find /path/ -type f 2>/dev/null | xargs -i grep -l "search" {}

แล้วก็… คำสั่ง replace

perl -pi -w -e 's/search/replace/g;' filename

ทีนี้ก็… เอามารวมร่างกัน ใช้แค่คำสั่งนี้อันเดียวจบ

find /path/ -type f 2>/dev/null | xargs -i grep -l "search" {} | xargs perl -pi -w -e 's/search/replace/g;'

อ้างอิง: Linux – Search and replace over multiple files

Tags: , ,