![sed 명령을 사용하여 단어의 일부를 바꾸는 방법](https://linux55.com/image/194280/sed%20%EB%AA%85%EB%A0%B9%EC%9D%84%20%EC%82%AC%EC%9A%A9%ED%95%98%EC%97%AC%20%EB%8B%A8%EC%96%B4%EC%9D%98%20%EC%9D%BC%EB%B6%80%EB%A5%BC%20%EB%B0%94%EA%BE%B8%EB%8A%94%20%EB%B0%A9%EB%B2%95.png)
한 줄에 한 단어만 있는 파일이 있습니다. 각 줄에 있는 단어의 특정 부분을 제거하고 싶습니다. sed 명령을 사용하여 이 부분을 어떻게 삭제할 수 있나요? 전임자:
u_fox/u_snake/u_snail/u_plus/u_core/u_vector/u_divider_rad4_0_1/instanceFE_OFC209016_vx0_srcb_fdivsqrt_44(code0_lo6_poic_hpc_int3_vcell05p00)
이 부분을 제거하고 싶습니다. (code0_lo6_poic_hpc_int3_vcell05p00)
기본적으로 대괄호를 포함하여 대괄호 안에 있는 모든 항목입니다.
파일의 다른 모든 줄은 비슷한 패턴을 따릅니다.
답변1
sed -e 's/(.*)//' file
( 점( )으로 표시되고 문자열로 끝나는) (
로 시작하는 모든 문자를 제거합니다 . 이는 이 시퀀스의 모든 행에 대해 발생합니다..*
)
답변2
$ cut -d'(' -f1 file
u_fox/u_snake/u_snail/u_plus/u_core/u_vector/u_divider_rad4_0_1/instanceFE_OFC209016_vx0_srcb_fdivsqrt_44
답변3
grep을 사용하세요:
grep -o '^[^(]*' file
열 포함:
column -ts'(' -H2 file
답변4
Below mentioned Awk command will do
awk -F "(" '{print $1}' filename ==========>This will display output
awk -F "(" '{print $1}' filename >tmpfile && mv tmpfile filename ======> If you want to save output in exsisting file