2013-06-20 1 views
1

내가 좋아하는 라인이 포함 된 텍스트 파일이 있습니다백 스페이스 및 단어로 단어를 어떻게 배치합니까?

telephone xxxx 
telpassword xxxx 
telephone xxxx 
telpassword xxxx 
telephone xxxx 
telpassword xxxx 
telephone xxxx 
telpassword xxxx 
telephone xxxx 
telpassword xxxx 
telephone xxxx 
telpassword xxxx 

와 나는 같은 데이터를 포함하는 파일을 만들고 싶어하지만 라인 :

telephone xxxx telpasswordxxxx 
telephone xxxx telpasswordxxxx 
telephone xxxx telpasswordxxxx 
telephone xxxx telpasswordxxxx 
telephone xxxx telpasswordxxxx 

나는 시도 :

sed 's/telpassword/\btelpassword/g' 

그러나이 명령은 작동하지 않습니다. 나는 이런 식으로해야한다고 생각하지만, "backspace"명령을 어떻게 두는 지 알 수 없다.

도움 주셔서 감사합니다. sed one liners에서

답변

2

:

sed '$!N;s/\n/ /' inputfile 

AWK 사용 :

awk '!(NR%2){print p " " $0}{p=$0}' filename 
+0

안녕하세요, sed 명령이 작동하지만, 내 파일에 비어있는 몇 줄이 있다고 생각합니다. sed 명령을 "telpassword"또는 "telephone"문자열로 조정할 수 있습니까? –

+0

명령 앞에'grep tel |'를 추가하십시오. '| '를 추가하는 것을 잊지 마십시오. – devnull

0

내용 script.vim의 사용 :

set backup 
g/^telephone/ normal J 
saveas! output.txt 
q! 

R을 유엔이 좋아 :

vim -u NONE -N -S script.vim infile 

그것은 내용과 파일 output.txt을 생성합니다 :

telephone xxxx telpassword xxxx 
telephone xxxx telpassword xxxx 
telephone xxxx telpassword xxxx 
telephone xxxx telpassword xxxx 
telephone xxxx telpassword xxxx 
telephone xxxx telpassword xxxx 
+0

안녕하세요. Birei, 저는 solaris 8을 사용하고 있습니다. 정력이 없습니다. –

+0

을 (를) 주시겠습니까?이 스크립트를 .sh 또는 .ksh 용으로 조정할 수 있습니까? 고마워요 –

+0

@ VulturuStefan : 그건 다른 것입니다. 다른 답변의 해결책을 사용하십시오.'sed' 또는'awk'가 좋습니다. – Birei

1

이 작동합니다 :

awk '/tele/{printf "%s ",$0}/telp/{print $0}' inputFile 
0

를 사용하여 붙여 넣기 :

paste -d" " - - < filename