Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
3
Help us understand the problem. What is going on with this article?
@Outstrp

sedについて(という名の文字列操作まとめ)

More than 5 years have passed since last update.

毎回ぐぐるのがめんどくさいので備忘的に

最初に現れた文字列を置換するには

例:「aaa」を「bbb」に置換する場合

sed '1,/aaa/s/aaa/bbb/'

参考リンク

sedにて一番最初にマッチしたモノだけを置換するには

マッチした行だけ表示する

例:「aaa」を「bbb」に置換してマッチする行だけ表示

sed -n 's/aaa/bbb/p'

例:「aaa」にマッチする行だけ表示

sed -n '/bbb/p'

もしくは

grep 'bbb'

指定した文字列を含まない行だけ表示

sedじゃないけど

grep -v 'bbb'

改行を削除

sedじゃ(ry

tr -d '\n'

使うことは少ないと思うけどどうしてもsedでやりたい場合

sed ':loop; N; $!b loop; ;s/\n/,/g'

参考:改行を置換したい

3
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Outstrp

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
3
Help us understand the problem. What is going on with this article?