0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

備忘録--入出力とリダイレクト--

Posted at

おはよう、こんにちわ、こんばんわ。今日の自分
標準入出力を切り替えるリダイレクションについてだ!

誰か見てましたら間違ってたり追記したほうがよいことは是非ともご教示お願いします:sob:。。。

標準入出力とリダイレクション

・シェルにはリダイレクションという機能があるようだ

・リダイレクションで標準入力や標準出力をファイルに変更することが可能だ

・テキストデータをキーボードではなくファイルから入力が可能だ

仮に標準入力を画面ではなくファイルで出力したければ下記だ↓↓

コマンド_ファイル.JPG

例:現在の日付を表示するdateコマンドをdate.txtに書き込む

date_txt.JPG

上記ではコマンドdateをdate.txt(テキストファイル)として出力させてもらった。

結果をcatコマンドで開いてみるぞ↓
cat_date.JPG

見事に出力されている←

ちなみに下行に追記する場合は>>を使用するのだ
下記はdateコマンドの出力結果テキストにechoコマンドでHello!を追記した結果だ↓

txt_Hello.JPG

テキストデータをキーボードではなくファイルから入力

コマンドに続けてリダイレクション記号 < と入力元ファイルを指定することで、ファイル内容に対してコマンドを実行することができる

今回は一例として先程作成したdate.txtに対してgrepでHello!の行だけ抜き出してみよう

gfrep_Hello.JPG

こういうことも可能だ

締まらない終わり方だが立ち止まらずに次の章へ進むのだ!!

日進月歩だ、ありがとうございました。

0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?