Bash shell ---- substitute@sed

sed is a special editor modifying files automatically. If you want to write a program to make changes in a file, sed is the tool to use.

Now, I introduce the most basic command that called substitution(s). The other commands will be introduced in other articles.

1.sed s/day/night/ day_file

There are four parts of this command.

s: substitute command

/../../: delimiter

day: regular expressiojn pattern for searching

night: replace string

This command will replace the first 'day' with 'night' line by line and show the results to the std. Attention: this command will not change the day_file.

b_large_Vh9l_744500000d871261.jpg

2.sed s/day/night/g day_file

This command will replace every 'day' with 'night' line by line and show the results to the std. Attention: this command will not change the day_file. And g means global.

b_large_BK4r_1041000002061262.jpg

3.sed s/day/night/g < day_file > night_file

This command will replace every 'day' with 'night' line by line and generate the night_file to store the result. Attention: this command will not change the day_file.

b_large_7LL7_2fb0000029f91262.jpg

4.sed s/day/night/g day_file > day_file_bak; mv day_file_bak day_file

This command will replace every 'day' with 'night' line by line and make changes to the day_file.(In fact, the command generate a new file named 'day_file_bak' to store the results and rename the 'day_file_bak' to 'day_file'. 

b_large_aAKi_154000002d451263.jpg

转载于:https://www.cnblogs.com/Neoh/archive/2012/09/28/2706989.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值