如何根据unix中的文件中的某些字符串清除文件中的特定行

时间:2014-09-02 11:10:57

标签: shell unix awk sed

我有一个文件如下 -

Password:   
Msg 2401, Level 11, State 2:  
Server 'test':  
Character set conversion is not available between client character set 'utf8' and server character set 'iso_1'.  
No conversions will be done.  
|Extraction_Date|Agent_Cde_1|Agent_Cde_2|Agent_Cde_3|Agent_Cde_4|Agent_Name  
|20140902       |0010       |       NULL|       NULL|       NULL|NULL  

我想删除列名前面的所有行。列名称之前的行数可能每次都有所不同。有没有什么方法可以检查'Extraction_date'字符串并使用unix命令删除它上面的所有行?

3 个答案:

答案 0 :(得分:2)

这将打印从Extraction日期开始的所有行:

awk '/^\|Extraction_Date/ {f=1} f' file
|Extraction_Date|Agent_Cde_1|Agent_Cde_2|Agent_Cde_3|Agent_Cde_4|Agent_Name  
|20140902       |0010       |       NULL|       NULL|       NULL|NULL

或者这可能没问题:

awk '/^\|/' file

答案 1 :(得分:1)

尝试使用grep命令

grep -F '|'

答案 2 :(得分:1)

使用 sed 地址范围:

sed -n '/^|Extraction_Date/,$p' file
相关问题