패턴 일치 뒤에 공백을 삽입하고 패턴을 다른 단어로 바꿉니다.

패턴 일치 뒤에 공백을 삽입하고 패턴을 다른 단어로 바꿉니다.

패턴 일치 후 공백을 삽입하는 방법

파일에 데이터가 있습니다

cellAN2D
input a1
output z
cellAIOI2D2
input a2
output z2
cellXOR2
input b1
output zn

패턴이 발견될 때마다 그 뒤에 공백을 추가하고 싶습니다. 출력은 다음과 같습니다

cell AN2D
input a1
output z
cell AIOI2D2
input a2
output z
cell XOR2
input b1
output z

나는 노력했다

sed  's/^cell/cell /g' file

그러나 그것은 작동하지 않았습니다.

또한 위 출력의 셀 단어를 출력을 제공하는 모듈 단어로 바꾸고 싶습니다.

module AN2D
input a1
output z
module AIOI2D2
input a2
output z
module XOR2
input b1
output z

이 두 단계를 결합하여 최종 출력을 얻을 수 있습니까?

답변1

다음을 시도해 보십시오:

$ sed 's/^cell/module /' file | tee outfile && mv outfile file
module AN2D
input
output
module AIOI2D2
input
output
module XOR2
input
output

$ cat file
module AN2D
input
output
module AIOI2D2
input
output
module XOR2
input
output
$

관련 정보