LoginSignup
2
2

More than 5 years have passed since last update.

2つのファイルの重複している行を出力するシェルスクリプト

Last updated at Posted at 2015-07-09

※追記:cat a.txt b.txt | sort | uniq -d で解決します

worseway
  1 #!/bin/bash
  2 
  3 if [ $# = 0 ] ; then
  4   echo "set 2args"
  5   exit 1
  6 fi
  7 
  8 if [ ! -f $1 ] ; then
  9   echo "no such file: $1"
 10   exit 1
 11 fi
 12 
 13 if [ ! -f $2 ] ; then
 14   echo "no such file $2"
 15   exit 1
 16 fi
 17 
 18 cat $1 | while read line1
 19 do
 20   cat $2 | while read line2
 21   do
 22     if [ $line1 = $line2 ] ; then
 23       echo $line1
 24     fi
 25   done
 26 done

※データ多いと死にます。ハッシュマップ使いたいすね。

2
2
7

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