다음 파일이 있습니다: main.txt
/F/FID/FID/000001/0/20180215//1/2/
/F/FID/FID/000002/0/20180215//1/2/
/F/FID/FID/000003/0/20180215//1/2/
/F/FID/FID/000004/0/20180215//1/2/
/F/FID/FID/000005/0/20180215//1/2/
/F/FID/FID/000006/0/20180215//1/2/
나는 sed를 사용하여 두 줄마다 새 파일을 인쇄하는 것을 좋아합니다.
파일 1.txt
/F/FID/FID/000001/0/20180215//1/2/
/F/FID/FID/000002/0/20180215//1/2/
파일 2.txt
/F/FID/FID/000003/0/20180215//1/2/
/F/FID/FID/000004/0/20180215//1/2/
파일 3.txt
/F/FID/FID/000005/0/20180215//1/2/
/F/FID/FID/000006/0/20180215//1/2/
답변1
쉽지 sed
는 않지만
awk 'NR%2 {fname = sprintf("file%d.txt", ++n)} {print > fname}' main.txt
주다
head file*.txt
==> file1.txt <==
/F/FID/FID/000001/0/20180215//1/2/
/F/FID/FID/000002/0/20180215//1/2/
==> file2.txt <==
/F/FID/FID/000003/0/20180215//1/2/
/F/FID/FID/000004/0/20180215//1/2/
==> file3.txt <==
/F/FID/FID/000005/0/20180215//1/2/
/F/FID/FID/000006/0/20180215//1/2/
또는,
split --lines=2 --numeric-suffixes=1 --suffix-length=1 --additional-suffix='.txt' main.txt 'file'
(이러한 옵션 중 일부는 GNU 버전에만 해당될 수 있습니다 split
.)