grep -A1 형식 출력

grep -A1 형식 출력

여러 IP 핑 테스트 결과가 포함된 파일이 10개 있습니다.

--- 10.90.101.224 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
Some Text here...
--- 10.90.101.225 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
Some Text here...
--- 10.90.101.226 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms

나는 >를 사용 grep -A1 'ping statistics' *.log하고 다음과 같은 결과를 얻습니다.

--- 10.90.101.224 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
--- 10.90.101.225 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
--- 10.90.101.226 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms

다음 형식으로 출력을 얻고 싶습니다

--- 10.90.101.224 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2002ms
--- 10.90.101.225 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2002ms
--- 10.90.101.226 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2002ms

답변1

사용 paste:

grep -A1 'ping statistics' *.log | paste - -

paste기본값은 줄 사이에 탭 문자를 추가합니다. 이를 have로 변경합니다 paste -d ' ' - -.

답변2

사용xargs

grep -A1 'ping statistics' *.log | xargs -n 15

-n max-args 명령줄당 최대 max-args개의 인수를 사용합니다.

관련 정보