카테고리 없음
[Shell(쉘)] 예제: 같은 파일 확장자 합치기 (작성중)
2026. 1. 13. 10:43반응형
#!/bin/bash
total=0
# -asd_cc.txt로 끝나는 모든 파일을 찾아서 라인 수를 더함
for file in *-asd_cc.txt; do
# 파일이 실제로 존재하는지 확인 (glob 패턴이 매칭되지 않을 경우 대비)
if [ -f "$file" ]; then
lines=$(wc -l < "$file")
total=$((total + lines))
echo "$file: $lines lines"
fi
done
# 결과를 total-asd_cc.txt에 저장
echo "$total" > total-asd_cc.txt
echo "Total lines: $total"
echo "Result saved to total-asd_cc.txt"
# 한 줄로 모든 파일 합치기
cat *-asd.cc.txt > merged-asd.cc.txt
반응형
