%20%EC%B2%98%EC%9D%8C%EC%9C%BC%EB%A1%9C%20%EC%9D%BC%EC%B9%98%ED%95%98%EB%8A%94%20%EB%B6%80%EB%B6%84%20%EB%AC%B8%EC%9E%90%EC%97%B4%EC%9D%84%20%EC%96%BB%EB%8A%94%20%EB%B0%A9%EB%B2%95%EC%9D%80%20%EB%AC%B4%EC%97%87%EC%9E%85%EB%8B%88%EA%B9%8C%3F.png)
다음 내용이 포함된 파일이 있습니다.
/hello="somestuffsomestuffsomestuffsomestuffsomestuffsomestuffsomestuff
somestuffsomestuffsomestuffsomestuffsomestuffsomestuffsomestuff
somestuffsomestuffsomestuffsomestuffsomestuffsomestuffsomestuff"
/hello="morestuffmorestuffmorestuffmorestuffmorestuffmorestuffmorestuff
morestuffmorestuffmorestuffmorestuffmorestuff"
어떻게 정의를 얻을 수 있습니까?
/hello="somestuffsomestuffsomestuffsomestuffsomestuffsomestuffsomestuff
somestuffsomestuffsomestuffsomestuffsomestuffsomestuffsomestuff
somestuffsomestuffsomestuffsomestuffsomestuffsomestuffsomestuff"
sed
파이프를 통해 "/"로 구분된 /hello
콘텐츠를 받고 있지만 cut
첫 번째 하위 문자열을 얻는 방법을 모르겠습니다.
내가 사용한 명령
sed -n '/hello/, /\"/ p' file.txt | cut -d "/" -f 2
어떤 이유로 각 하위 문자열을 첫 번째 줄과 나머지 줄로 나눕니다.
답변1
다음 중 하나를 사용하세요.
sed -n '/hello/,/"$/p;/"$/q' infile
또는 이 방정식은 다음과 같습니다.
sed '/hello/,/"$/!d;/"$/q' infile
또는 awk
다음과 같이 사용할 수도 있습니다(항상 첫 번째 줄이 있다고 가정 hello
).
awk '/hello/ || 1;/"$/{exit}' infile
그렇지 않으면 플래그를 사용하여 관리하세요.
awk '/hello/{prnt=1};prnt;/"$/{exit}' infile
답변2
나는 다음 sed 명령을 사용하여 이 작업을 수행했습니다.
sed '0,/hello.*/!s///' inputfile| sed '/^\/$/,$d'
산출
/hello="somestuffsomestuffsomestuffsomestuffsomestuffsomestuffsomestuff
somestuffsomestuffsomestuffsomestuffsomestuffsomestuffsomestuff
somestuffsomestuffsomestuffsomestuffsomestuffsomestuffsomestuff"
답변3
또 다른 방법
sed -n '/\/hello/,/"$/p;/"$/q' iputfile
산출
/hello="somestuffsomestuffsomestuffsomestuffsomestuffsomestuffsomestuff
somestuffsomestuffsomestuffsomestuffsomestuffsomestuffsomestuff
somestuffsomestuffsomestuffsomestuffsomestuffsomestuffsomestuff"