単一のコマンドラインを使用してUnix txtファイルから特定のパターンに一致する文字列全体を削除する方法

単一のコマンドラインを使用してUnix txtファイルから特定のパターンに一致する文字列全体を削除する方法

「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

おすすめ記事