
"vcc"가 포함된 모든 문자열을 제거하고 싶습니다.
예:
s_regscan_ctrl_lab_2_regscan_ce[0] s_regscan_data_l_regscan s_t_regscan_data_tieoff_regscan vcc_cram_viort1_6_t
vcc_cram_viort1_7_t vcc_cram_viort1_8_t vcc_cram_viort1_9_t vcc_cram_vioxio1_0_t
vcc_cram_vioxio1_1_t vcc_cram_vioxio1_2_t vcc_cram_vioxio2_0_t vcc_cram_vioxio2_1_t
vcc_cram_vioxio2_2_t vcchg vccl vssgnd m_b_regscan_data_tieoff_regscan
예상 출력:
s_regscan_ctrl_lab_2_regscan_ce[0] s_regscan_data_l_regscan s_t_regscan_data_tieoff_regscan vssgnd m_b_regscan_data_tieoff_regscan
나는 이전에 시도했습니다:
cat abc.txt | sed 's/\svcc.*\s//g'"
그러나 vcc* 이후의 모든 항목을 제거하고 다음을 반환합니다.
s_regscan_ctrl_lab_2_regscan_ce[0] s_regscan_data_l_regscan s_t_regscan_data_tieoff_regscan
누구든지 도와줄 수 있나요?
답변1
태그한 이후로티클
$ cat abc.txt
s_regscan_ctrl_lab_2_regscan_ce[0] s_regscan_data_l_regscan s_t_regscan_data_tieoff_regscan vcc_cram_viort1_6_t
vcc_cram_viort1_7_t vcc_cram_viort1_8_t vcc_cram_viort1_9_t vcc_cram_vioxio1_0_t
vcc_cram_vioxio1_1_t vcc_cram_vioxio1_2_t vcc_cram_vioxio2_0_t vcc_cram_vioxio2_1_t
vcc_cram_vioxio2_2_t vcchg vccl vssgnd m_b_regscan_data_tieoff_regscan
우리가 remove_vcc.tcl
가지고 있다면
#!/usr/bin/env tclsh
set fid [open [lindex $argv 0] r]
while {[gets $fid line] != -1} {
set words [split $line]
set filtered [lmap word $words {
if {[string match {*vcc*} $word]} then continue else {string cat $word}
}]
set newline [join $filtered]
if {[string trim $newline] ne ""} {
puts $newline
}
}
close $fid
그 다음에
$ tclsh remove_vcc.tcl abc.txt
s_regscan_ctrl_lab_2_regscan_ce[0] s_regscan_data_l_regscan s_t_regscan_data_tieoff_regscan
vssgnd m_b_regscan_data_tieoff_regscan
답변2
어떻게 진행하고 싶으신지 잘 모르겠지만 시도해 보겠습니다.
텍스트 파일에서 모든 문자열을 삭제하려면 vcc
다음을 사용할 필요가 없습니다 cat
.
sed 's/vcc//g' abc.txt
-i
명령 의 스위치를 사용하여 sed
파일에 수정 사항을 기록합니다.
다음을 포함하는 모든 줄을 삭제하려면 vcc
:
grep -v "vcc" abc.txt
모든 단어를 제거하려면(여기서는 공백으로 구분된 문자열을 의미합니다):
sed 's/\b\w*vcc\w*\b//g' abc.txt
답변3
나는 다음과 같은 간단한 한 줄짜리를 사용하겠습니다 awk
.
cat abc.txt | awk -v RS=" " '!/vcc/ {print $0}'
vcc
또는 귀하의 예에서 제 생각 에는 어딘가에 포함시키는 대신 처음에 있으면 제거하고 싶기 때문에 다음을 사용하는 것이 좋습니다.
cat abc.txt | awk -v RS=" " '!/^vcc/ {print $0}'
답변4
사용 awk
:
$ awk '{for(i=1;i<=NF;i++) printf "%s", ($i ~ /vcc/) ? "" : $i OFS}END{print ""}' file