LoginSignup
0
1

More than 5 years have passed since last update.

Shell メモ書き

Last updated at Posted at 2017-06-01

shellでファイルを読み込んで 置換したり、検索したりする時に便利。

まずファイルを読む

読ませるファイル

test.txt
hoge
piyo
huga

piyos
hoges
hugas

piyoing
hogeing
hugaing

shellの使い方

変数に代入し表示

read.sh
#!/bin/sh

text=`cat test.txt`
echo $text

hoge piyo huga piyos hoges hugas piyoing hogeing hugaing

結果を複数行で表示

read.sh
#!/bin/sh

text=`cat test.txt`
echo "$text"
hoge
piyo
huga

piyos
hoges
hugas

piyoing
hogeing
hugaing

指定した文字列の行を表示

read.sh
#!/bin/sh

text=`cat test.txt | grep hoge`
echo "$text"
hoge
hoges
hogeing

指定した文字列のみを表示、重複を一括表示

read.sh
#!/bin/sh

text=`cat test.txt | grep -o hoge | uniq`
echo "$text"
hoge

最後

なんかつかえそう

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1