sed -e '$!d'가 예상대로 작동하지 않습니까?

sed -e '$!d'가 예상대로 작동하지 않습니까?

내가 실행할 때 :

sudo /usr/local/nginx/sbin/nginx -t

나는 돌아왔다:

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

나는 마지막 행만 원하므로 다음을 실행합니다.

sudo /usr/local/nginx/sbin/nginx -t | sed -e '$!d'

그러나 sed가 없는 것과 동일한 결과를 얻습니다.

답변1

명령이 stdout 대신 stderr로 출력될 수 있습니다. stderr를 stdout으로 리디렉션합니다.

sudo /usr/local/nginx/sbin/nginx -t 2>&1 | sed -e '$!d'

출력의 마지막 줄만 원하는 경우 tail -n 1대신 사용할 수도 있습니다 sed.

관련 정보