Giter Club home page Giter Club logo

myuniq's Introduction

Myuniq

UNIXコマンドのuniqをスクラッチ実装したものです.
外部ライブラリなどは不使用で,Cの標準ライブラリのみでコンパイルできます.

以下はオプションなどの解説です.

コマンド

uniq - ファイルの行を読み込み重複する行を削除し、出力する。

書式

uniq [option]... [filePath]

説明

uniqは、指定したファイルまたは標準入力を読み込み、重複行をオプションに従って処理して、標準出力に出力する。 0個以上のオプションを指定でき、ファイルは一つ指定できる。 もし、option 指定なしの場合、重複した行は1度だけ出力し、重複しない行はそのまま出力する。 ただし、入力されるファイルはソート済みであること。

オプション

-c 重複した行の数と行の内容を表示する
-i 英文字の大文字小文字を無視して判定する。例)aとAは同じとみなす。
-u 重複した行を出力せず、重複していない行のみを出力する。
-V バージョン情報を出力する。他のオプションとの併用は不可能なのでエラーを出力する。

戻り値

正常終了時の戻り値は0、エラー時は1以上の値を戻り値とする。

エラー処理

  • 上記で示したオプション以外を指定したとき、下記Usageを出力し終了する。
$ uniq -z hoge.dat
Usage: uniq [option] [filePath] \n);
-c 重複した行と重複していない行のそれぞれの数と行の内容を表示する。
-i 英文字の大文字小文字を無視して判定する。例)aとAは同じとみなす。
-u 重複した行を出力せず、重複していない行のみを出力する。
-V バージョン情報を表示。
  • オプションの組み合わせが不正なとき下記メッセージを出力し、終了する
$ uniq -V -c hoge.dat
if you use -V, you cannot use it with other options.
(-V または--versionを使用する場合、ほかのオプションと併用できません。)
  • 存在しないファイルパスを入力したとき下記メッセージを出力し、終了する。
$ uniq /etc/not_exist.txt ## 存在しないファイルパス
uniq: /etc/not_exist.txt: No such file or directory

使用例(動作仕様)

hoge.txtを以下の内容とする。

A
A
B
B
b
C

出力例

  1. ファイルパスのみの入力
$ uniq hoge.txt
A
B
b
C

重複する行は一度しか表示されない。

  1. オプション指定(-c)
$ uniq -c hoge.txt
2 A
2 B
1 b
1 C

重複行の重複した行数と内容を出力する。

  1. リスト1オプション指定(-i)
$ uniq -i hoge.txt
A
B
C

重複の判定には大文字小文字を無視する。そして、重複行の最初の行を出力する。

  1. オプション指定(-u)
$ uniq -u hoge.txt
C

重複した行を出力せず、重複しない行のみを出力する。

  1. オプション指定(-i -c)
$ uniq -i -c hoge.txt
2 A
3 B
1 C

大文字小文字を無視し、重複回数と内容を出力する。

  1. オプション指定(-i -u)
$ uniq -i -u hoge.txt
C

大文字小文字を無視し、重複しない行のみを出力する。

myuniq's People

Contributors

stu-ijichi-shoya avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.