ファイルから行を読む

ファイルから行を読む

こんにちは、どのようにファイルの各行を読み、他のファイルと比較することができますか...実際には、ファイルはコマンドラインからインポートする必要があります...助けてください

if [[-f $@ ]];
    then
    for "$line" in $@;
    do
        if grep "^$line" /etc/passwd > /dev/null;
            then IFS=":";
            read usr pwd uid gid gcos home shell < <(grep "^$user" /etc/passwd);
            IFS=",";
            read name <<< "$gcos";
            printf "UID:%-10s Name:%s\n" "$uid" "$name";
        else
            echo "No User"
        fi
    done
fi

ベストアンサー1

こんにちは、ファイルの各行をどのように読み、他のファイルと比較できますか?

両方のファイルを比較したい場合は、次のことを提案できます。

オプション1違い=>ファイルの違いを並べてマージ

sdiff file1 file2

出力例:

abcdev                                                          abcdev
abcdev                                                          abcdev
abcdev                                                          abcdev
abcdev                                                        | abcde33

オプション#2違い=>ファイルを1行ずつ比較する

diff file1 file2

出力例:

4c4
< abcdev
---
> abcde33

オプション#3Wimdiv=> Vimを使用してファイルの2つ、3つ、または4つのバージョンを編集し、違いを表示します。

vimdiff file1 file2

例画面(違いを確認しながらファイルを編集できます):

ここに画像の説明を入力してください。

オプション#4grep=>パターンに一致するライン印刷

grep -Fxvf file1 file2

ロゴ分析:

-F, --fixed-strings
  Interpret PATTERN as a list of fixed strings, separated by newlines, any of which is to be matched.    
-x, --line-regexp
  Select only those matches that exactly match the whole line.
-v, --invert-match
  Invert the sense of matching, to select non-matching lines.
-f FILE, --file=FILE
  Obtain patterns from FILE, one per line.  The empty file contains zero patterns, and therefore matches nothing.

出力例:

abcde33

おすすめ記事