grep, sed, awk Notes

15 篇文章 0 订阅

overview: https://sunjian.blog.csdn.net/article/details/82930982

grep

detailed explanation and examples: https://xie1997.blog.csdn.net/article/details/82974781

grep pattern ==> match by text or linux wildcards

grep "pattern" ==> match by regular expression with soft escape (variable, command replacement allowed)

grep 'pattern' ==> match by regular expression with hard escape (use as simple text)

 

for linux wildcards vs. linux (E)RE: https://blog.csdn.net/youmatterhsp/article/details/80528761

for generic ERE rules: https://blog.csdn.net/scgaliguodong123_/article/details/45363409

 

sed

for detailed explanation and examples: https://www.cnblogs.com/xuxiuxiu/p/6945385.html

1. sed read the file into a stream and process the file content line by line

2. sed option edit_command filename ==> "sed -p filename"  will simply print the file line by line

===> all fancier manipulation of content selection and editting can be built up from here.

===> with neither output redirection nor -i option, NO sed command will edit the original file content; it will simply print the result to console.

3. (from https://sunjian.blog.csdn.net/article/details/82930982)

 

both 

sed '#a txt' filename

sed '#a\txt' filename 

work

4. 2 method for search/match and partially replace within a line:

from https://www.cnblogs.com/xuxiuxiu/p/6945385.html

One: Pipeline

Two: 

change the 's' edit command to 'd' to delete lines with matched pattern.

==> unfortunately back reference cannot be parsed across '/'

e.g.

sed -i '/\(\(la\)\{2,\}\)/s/\1/hihihi/g' file   // match lalala, replace lalala with hihihi

gives: invalid back reference

\(\) will group together expressions; not () (not for RE, though () should do the job for ERE. while \( matches the char '(' ).

la\{2,\} ==> laa.....

\(la\)\{2,\} ==> lala.......

 

awk

official doc for gawk: http://www.gnu.org/software/gawk/manual/gawk.html

intro and examples: https://www.cnblogs.com/ggjucheng/archive/2013/01/13/2858470.html

a mini programming language, a tool to disect the file and filter for particular patterns/info;

C-like; the most powerful of the 3 and can be cumbersome to deploy ==> use scripts to deal with complex instructions.

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值