perl -pie 플래그는 Perl을 강력한 다중 파일 인플레이스(in-place) 검색 및 치환 스트림 편집기로 변환합니다.
명령어 플래그 의미 (Command Flag Meanings)
perl -p -i -e 'code' file.txt
-p: 입력 행을 반복하고 각 행을 자동으로 출력 (sed와 유사).-i: 파일을 직접 수정(in-place). 백업 복사본을 유지하려면-i.bak사용.-e: 한 줄의 Perl 코드 실행.
검색 및 치환 예제 (Search & Replace Examples)
기본 전역 치환
# 모든 .txt 파일에서 'hello'를 'world'로 치환
perl -p -i -e 's/hello/world/g' *.txt
백업 파일 생성 포함 치환
# 원본을 수정하고 원본 복사본을 file.txt.bak로 저장
perl -p -i.bak -e 's/foo/bar/g' file.txt
정규식 및 역참조
# '@include align-items(center);'를 'align-items: center;'로 변환
perl -p -i -e 's/@include (align-items)\((.*)\);/$1: $2;/g' style.css