- 论坛徽章:
- 780
|
回复 27# Iinvincible
awk我可以写类似的,用index来判断当前行中是不是含有你想要的分割符,
但这种判断也有一定程度的不严谨性,它不保证当前行仅含有该分隔符。- sep='[abcd:/]';var='!!!!!ddddd';awk -vsep=$sep -vvar=$var 'index($0,sep)>0{k=1} k&&/^[[:space:]]*$/{k=0;print var} END{if(k)print var}1' i
- ###
- this is a test file
- [abcd:/]
- this is a test file
- this is a test file
- this is a test file
- this is a test file
- !!!!!ddddd
- ###
- [abcd:/efg]
- this is a test file
- this is a test file
- this is a test file
- this is a test file
- this is a test file
- this is a test file
- this is a test file
- his is a test file
- [abcd:/]
- 1111111111
- 22222222222
- this is a test file
- !!!!!ddddd
复制代码- cat i
- ###
- this is a test file
- [abcd:/]
- this is a test file
- this is a test file
- this is a test file
- this is a test file
- ###
- [abcd:/efg]
- this is a test file
- this is a test file
- this is a test file
- this is a test file
- this is a test file
- this is a test file
- this is a test file
- his is a test file
- [abcd:/]
- 1111111111
- 22222222222
- this is a test file
复制代码 |
|