데이터를 필터링하고 다음과 같은 CSV 파일을 만들었습니다.
%%TRACERT: IPTYPE=IPv4, LOCALIP4="10.10.10.10", PEERIP4="20.20.20.20", MAXHOP=10;%%
1,3,1,1,1,10.10.10.10
2,3,1,1,1,10.37.112.5
3,0,NULL,NULL,NULL,Timeout
4,0,NULL,NULL,NULL,Timeout
5,0,NULL,NULL,NULL,Timeout
6,3,1,1,1,20.20.20.20
%%TRACERT: IPTYPE=IPv4, LOCALIP4="30.30.30.30", PEERIP4="40.40.40.40", MAXHOP=10;%%
1,3,1,1,1,30.30.30.30
2,3,1,1,1,30.30.30.30
3,3,1,1,1,30.30.30.30
4,0,NULL,NULL,NULL,Timeout
5,3,1,1,1,40.40.40.40
6,3,1,1,1,40.40.40.40
7,3,1,1,1,40.40.40.40
%%TRACERT: IPTYPE=IPv4, LOCALIP4="50.50.50.50", PEERIP4="60.60.60.60", MAXHOP=10;%%
1,3,1,10,1,50.50.50.50
2,3,1,1,1,50.50.50.50
3,0,NULL,NULL,NULL,Timeout
4,3,1,1,1,50.50.50.50
5,3,1,1,1,50.50.50.50
6,3,1,1,1,60.60.60.60
7,3,1,1,1,60.60.60.60
8,3,1,1,1,60.60.60.60
각 %%TRACERT 행을 다음과 같은 홉으로 채우고 싶습니다.
1,3,1,1,1,10.10.10.10,%%TRACERT: IPTYPE=IPv4, LOCALIP4="10.10.10.10", PEERIP4="20.20.20.20", MAXHOP=10;%%
2,3,1,1,1,10.37.112.5,%%TRACERT: IPTYPE=IPv4, LOCALIP4="10.10.10.10", PEERIP4="20.20.20.20", MAXHOP=10;%%
3,0,NULL,NULL,NULL,Timeout,%%TRACERT: IPTYPE=IPv4, LOCALIP4="10.10.10.10", PEERIP4="20.20.20.20", MAXHOP=10;%%
4,0,NULL,NULL,NULL,Timeout,%%TRACERT: IPTYPE=IPv4, LOCALIP4="10.10.10.10", PEERIP4="20.20.20.20", MAXHOP=10;%%
5,0,NULL,NULL,NULL,Timeout,%%TRACERT: IPTYPE=IPv4, LOCALIP4="10.10.10.10", PEERIP4="20.20.20.20", MAXHOP=10;%%
6,3,1,1,1,20.20.20.20,%%TRACERT: IPTYPE=IPv4, LOCALIP4="10.10.10.10", PEERIP4="20.20.20.20", MAXHOP=10;%%
1,3,1,1,1,30.30.30.30,%%TRACERT: IPTYPE=IPv4, LOCALIP4="30.30.30.30", PEERIP4="40.40.40.40", MAXHOP=10;%%
2,3,1,1,1,30.30.30.30,%%TRACERT: IPTYPE=IPv4, LOCALIP4="30.30.30.30", PEERIP4="40.40.40.40", MAXHOP=10;%%
3,3,1,1,1,30.30.30.30,%%TRACERT: IPTYPE=IPv4, LOCALIP4="30.30.30.30", PEERIP4="40.40.40.40", MAXHOP=10;%%
4,0,NULL,NULL,NULL,Timeout,%%TRACERT: IPTYPE=IPv4, LOCALIP4="30.30.30.30", PEERIP4="40.40.40.40", MAXHOP=10;%%
5,3,1,1,1,40.40.40.40,%%TRACERT: IPTYPE=IPv4, LOCALIP4="30.30.30.30", PEERIP4="40.40.40.40", MAXHOP=10;%%
6,3,1,1,1,40.40.40.40,%%TRACERT: IPTYPE=IPv4, LOCALIP4="30.30.30.30", PEERIP4="40.40.40.40", MAXHOP=10;%%
7,3,1,1,1,40.40.40.40,%%TRACERT: IPTYPE=IPv4, LOCALIP4="30.30.30.30", PEERIP4="40.40.40.40", MAXHOP=10;%%
1,3,1,10,1,50.50.50.50,%%TRACERT: IPTYPE=IPv4, LOCALIP4="50.50.50.50", PEERIP4="60.60.60.60", MAXHOP=10;%%
2,3,1,1,1,50.50.50.50,%%TRACERT: IPTYPE=IPv4, LOCALIP4="50.50.50.50", PEERIP4="60.60.60.60", MAXHOP=10;%%
3,0,NULL,NULL,NULL,Timeout,%%TRACERT: IPTYPE=IPv4, LOCALIP4="50.50.50.50", PEERIP4="60.60.60.60", MAXHOP=10;%%
4,3,1,1,1,50.50.50.50,%%TRACERT: IPTYPE=IPv4, LOCALIP4="50.50.50.50", PEERIP4="60.60.60.60", MAXHOP=10;%%
5,3,1,1,1,50.50.50.50,%%TRACERT: IPTYPE=IPv4, LOCALIP4="50.50.50.50", PEERIP4="60.60.60.60", MAXHOP=10;%%
6,3,1,1,1,60.60.60.60,%%TRACERT: IPTYPE=IPv4, LOCALIP4="50.50.50.50", PEERIP4="60.60.60.60", MAXHOP=10;%%
7,3,1,1,1,60.60.60.60,%%TRACERT: IPTYPE=IPv4, LOCALIP4="50.50.50.50", PEERIP4="60.60.60.60", MAXHOP=10;%%
8,3,1,1,1,60.60.60.60,%%TRACERT: IPTYPE=IPv4, LOCALIP4="50.50.50.50", PEERIP4="60.60.60.60", MAXHOP=10;%%
답변1
따라서 다음으로 시작하는 줄을 저장 %%TRACRT:
하고 이를 다음 선취권에 연결합니다.
awk '/^%%TRACERT:/ {sfx = $0; next} {print $0 "," sfx}' data
답변2
any를 사용하면 이전 공간 에 행을 저장 하고 삭제할 sed
수 있으며 , 다른 행은 추가로 예약된 공간을 확보 하고 (추가로 인해 발생하는) 개행 문자를 쉼표로 바꿀 수 있습니다.%%TRACERT
h
d
G
sed '/%%TRACERT/{h;d;};G;s/\n/,/' file.csv