두 줄로 작성된 파일에 줄을 결합하고 싶습니다. 예를 들어 아래와 같이 각각 속담과 저자 이름이있는 첫 번째 줄과 두 번째 줄을 연결하고 싶습니다. 모든 유사한 사건을 파일에 결합하고 싶습니다.
Shift + J를 사용하여 수동으로 결합 할 수 있지만 거의 10000 개의 줄이 있고하기가 매우 어려워졌습니다.
그래서 줄의 시작 부분에 숫자가 있고 점, 그리고 공백, 그리고 텍스트가있는 모든 줄을 검색해서 결합하고 싶습니다. ^ [0-9] *. (118.) 그리고 줄의 시작 부분에 숫자가없는 다음 줄. 그래서 그들과 함께하십시오.
나는 모든 곳을 검색하고 그것을 구현하려고 시도했지만 아무 소용이 없습니다.
118. People don't care how much you know until they know how much they care.
John C. Maxwell
119. A life lived in fear is a life half lived. - Proverb
120. Nothing great was ever achieved without enthusiasm.
Ralph Waldo Emerson
121. Damn the torpedoes, full speed ahead. - David Farragut
122. Our lives begin to end the day we become silent about things that matter. -
Martin Luther King, Jr.
이렇게해야합니다.
awk '/^[0-9]+\./ { if (last) print last; last = $0; next }
{ print last, $0; last = "" }'
주어진 데이터 파일 :
118. People don't care how much you know until they know how much they care.
John C. Maxwell
119. A life lived in fear is a life half lived. - Proverb
120. Nothing great was ever achieved without enthusiasm.
Ralph Waldo Emerson
121. Damn the torpedoes, full speed ahead. - David Farragut
122. Our lives begin to end the day we become silent about things that matter. -
Martin Luther King, Jr.
그러면 출력이 생성됩니다.
118. People don't care how much you know until they know how much they care. John C. Maxwell
119. A life lived in fear is a life half lived. - Proverb
120. Nothing great was ever achieved without enthusiasm. Ralph Waldo Emerson
121. Damn the torpedoes, full speed ahead. - David Farragut
122. Our lives begin to end the day we become silent about things that matter. - Martin Luther King, Jr.
코드는 하나의 연속 줄만 있다고 가정합니다. 연속 줄이 여러 개있을 수 있다면 더 복잡한 스크립트가 필요합니다.
$ cat new.data
118. People don't care how much you know until they know how much they care.
John C. Maxwell
119. A life lived in fear is a life half lived. - Proverb
120. Nothing great was ever achieved without enthusiasm.
Ralph Waldo Emerson
121. Damn the torpedoes, full speed ahead. - David Farragut
122. Our lives begin to end the day we become silent about things that matter. -
Martin Luther King, Jr.
123. More than one line of data causes trouble for the basic script.
A more complex script can deal with those too. -
Jonathan Leffler
$ awk '/^[0-9]+\./ { if (last) print last; last = $0; next }
> { last = last " " $0 }
> END { if (last) print last }' new.data
118. People don't care how much you know until they know how much they care. John C. Maxwell
119. A life lived in fear is a life half lived. - Proverb
120. Nothing great was ever achieved without enthusiasm. Ralph Waldo Emerson
121. Damn the torpedoes, full speed ahead. - David Farragut
122. Our lives begin to end the day we become silent about things that matter. - Martin Luther King, Jr.
123. More than one line of data causes trouble for the basic script. A more complex script can deal with those too. - Jonathan Leffler
$
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다