![-print0에서 마지막 n자를 제거하시겠습니까?](https://linux55.com/image/90878/-print0%EC%97%90%EC%84%9C%20%EB%A7%88%EC%A7%80%EB%A7%89%20n%EC%9E%90%EB%A5%BC%20%EC%A0%9C%EA%B1%B0%ED%95%98%EC%8B%9C%EA%B2%A0%EC%8A%B5%EB%8B%88%EA%B9%8C%3F.png)
현재 나는 다음을 가지고 있습니다:
@find . -type f -name "img*_01.png" -print0 | python script.py -f {}
이와 같이 마지막 몇 글자를 자르는 방법이 있습니까?
@find . -type f -name "img*_01.png" -print0 | python script.py -f {}.rightTrim(n)
답변1
당신이 의미한다고 가정하면 :
find . -type f -name "img*_01.png" -print0 |
xargs -r0I{} python script.py -f {}
없음 xargs
으로 인해 완료하는 데 사용할 수 없습니다.xargs
오른쪽 트림()운영자. 취소 하고 ( , 구문) xargs
과 같은 작업을 수행 할 수 있습니다.bash
zsh
find . -type f -name "img*_01.png" -print0 |
while IFS= read -rd '' file; do
python script.py -f "${file%?????}"
done
또는 유지 xargs
하되 셸을 호출하여 가지치기 작업을 수행합니다.
find . -type f -name "img*_01.png" -print0 | xargs -r0 sh -c '
for file do
python script.py -f "${file%?????}"
done' sh
하지만 이 경우 표준 -exec {} +
구문을 사용할 수도 있습니다.
find . -type f -name "img*_01.png" -exec sh -c
for file do
python script.py -f "${file%?????}"
done' sh {} +
또는 (전체 파일 이름이 필요하지 않은 경우) 각 파일 이름의 마지막 5자를 자르는 명령으로 출력을 파이프합니다.
sed -zE 's/.{5}$//' # assuming recent GNU sed
또는
awk -v RS='\0' -v ORS='\0' '{print substr($0,1,length-5)}'
awk
(GNU 또는 최신 버전을 가정 mawk
).
GNU 시스템에서는 기본 단일 작업 유틸리티를 사용하여 이를 수행할 수도 있습니다.
tr '\n\0' '\0\n' | rev | cut -c 6- | rev | tr '\n\0' '\0\n'
그리고 항상 다음이 있습니다 perl
.
perl -0 -pe 's/.{5}$//'
perl -0 -lpe 'chop;chop;chop;chop;chop'
perl -0 -lpe 'substr($_,-5,5,"")'