아래 내용이있는 lftp 로그 파일이 있습니다.
2020-10-22 09:28:47 /test/scripts/tmp/george1.txt -> sftp://[email protected]/test/scripts/tmp/george1.txt 0-5 2.8 KiB/s
2020-10-22 09:28:48 /test/scripts/tmp/george2.txt -> sftp://[email protected]/test/scripts/tmp/george2.txt 0-12 6.3 KiB/s
2020-10-22 09:28:49 /test/scripts/tmp/george3.txt -> sftp://[email protected]/test/scripts/tmp/george3.txt 0-27 15.4 KiB/s
날짜, 시간, 파일 이름 및 바이트 만 있으므로 다음과 같이 얻고 싶습니다.
2020-10-22 09:28:47 george1.txt 5
2020-10-22 09:28:48 george2.txt 12
2020-10-22 09:28:49 george3.txt 27
가까이 오는 awk, sed 스크립트가 있지만 파일 이름 앞에 쓰레기를 태우는 방법을 알 수 없습니다.
awk '{print $1, $2, $5,$6}' transfer1.log | sed -r -e 's/ [0-9]+-/ /' >
transfer_formatted.log. 결과 :
2020-10-22 09:28:47 sftp://[email protected]/test/scripts/tmp/george1.txt 5
2020-10-22 09:28:48 sftp://[email protected]/test/scripts/tmp/george2.txt 12
2020-10-22 09:28:49 sftp://[email protected]/test/scripts/tmp/george3.txt 27
누군가 sed 부분으로 나를 도울 수 있습니까?
awk
대체도 지원합니다.
$ awk '{sub(/.*\//, "", $5); sub(/[0-9]+-/, "", $6); print $1, $2, $5, $6}' ip.txt
2020-10-22 09:28:47 george1.txt 5
2020-10-22 09:28:48 george2.txt 12
2020-10-22 09:28:49 george3.txt 27
또는 마지막 두 열이 -
입력 샘플에 표시된대로 문자를 가질 수 없다고 가정합니다 .
$ sed -E 's|/.*/([^ ]+) [0-9]+-([0-9]+).*|\1 \2|' ip.txt
2020-10-22 09:28:47 george1.txt 5
2020-10-22 09:28:48 george2.txt 12
2020-10-22 09:28:49 george3.txt 27
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다