パス名の最初の部分と行末の数字と一致します。

パス名の最初の部分と行末の数字と一致します。

findgrepaとパイプには、次の種類の出力があります。

./Columbia/815425_0001104659-11-049107.txt:         CENTRAL INDEX KEY:              0000815425
./Columbia/815425_0001104659-12-060231.txt:         CENTRAL INDEX KEY:              0000815425
./Columbia/815425_0001104659-13-066298.txt:         CENTRAL INDEX KEY:              0000815425
./Dimensional Advisors/355437_0001137439-04-000108.txt:         CENTRAL INDEX KEY:              0000355437
./Dimensional Advisors/355437_0001137439-05-000205.txt:         CENTRAL INDEX KEY:              0000355437
./Dimensional Advisors/355437_0001137439-06-000306.txt:         CENTRAL INDEX KEY:              0000355437
./Dimensional Advisors/355437_0001137439-08-000364.txt:         CENTRAL INDEX KEY:              0000355437
./Dimensional Advisors/355437_0001137439-09-000076.txt:         CENTRAL INDEX KEY:              0000355437
./Dimensional Advisors/355437_0001137439-12-000295.txt:         CENTRAL INDEX KEY:              0000355437
./Dimensional Advisors/355437_0001140361-10-035592.txt:         CENTRAL INDEX KEY:              0000355437

欲しい

Columbia 0000815425
Columbia 0000815425
Columbia 0000815425
Dimensional Advisors 0000355437
Dimensional Advisors 0000355437
Dimensional Advisors 0000355437
Dimensional Advisors 0000355437
Dimensional Advisors 0000355437
Dimensional Advisors 0000355437
Dimensional Advisors 0000355437

考えていますsedが、grepどのように合わせるか混乱します:マッチングパート1:(私はどのようにマッチングしますか/?)

erik Funds$ cat myoutput | egrep -o "[A-Z].*/"
Columbia/
Columbia/
Columbia/
Dimensional Advisors/
Dimensional Advisors/
Dimensional Advisors/
Dimensional Advisors/
Dimensional Advisors/
Dimensional Advisors/
Dimensional Advisors/

最後の10桁の数字は次のとおりです。

erik Funds$ cat myoutput | egrep -o "[0-9]{10}$"
0000815425
0000815425
0000815425
0000355437
0000355437
0000355437
0000355437
0000355437
0000355437
0000355437

ベストアンサー1

awkフィールド区切り記号として使用し、/フィールド2とフィールド3を印刷します(必要な0パディングを使用)。

... | awk -F/ '{ printf("%s %010d\n", $2, $3) }'

例:

$ cat file.txt 
./Columbia/815425_0001104659-11-049107.txt:         CENTRAL INDEX KEY:              0000815425
./Columbia/815425_0001104659-12-060231.txt:         CENTRAL INDEX KEY:              0000815425
./Columbia/815425_0001104659-13-066298.txt:         CENTRAL INDEX KEY:              0000815425
./Dimensional Advisors/355437_0001137439-04-000108.txt:         CENTRAL INDEX KEY:              0000355437
./Dimensional Advisors/355437_0001137439-05-000205.txt:         CENTRAL INDEX KEY:              0000355437
./Dimensional Advisors/355437_0001137439-06-000306.txt:         CENTRAL INDEX KEY:              0000355437
./Dimensional Advisors/355437_0001137439-08-000364.txt:         CENTRAL INDEX KEY:              0000355437
./Dimensional Advisors/355437_0001137439-09-000076.txt:         CENTRAL INDEX KEY:              0000355437
./Dimensional Advisors/355437_0001137439-12-000295.txt:         CENTRAL INDEX KEY:              0000355437
./Dimensional Advisors/355437_0001140361-10-035592.txt:         CENTRAL INDEX KEY:              0000355437

$ awk -F/ '{ printf("%s %010d\n", $2, $3) }' file.txt
Columbia 0000815425
Columbia 0000815425
Columbia 0000815425
Dimensional Advisors 0000355437
Dimensional Advisors 0000355437
Dimensional Advisors 0000355437
Dimensional Advisors 0000355437
Dimensional Advisors 0000355437
Dimensional Advisors 0000355437
Dimensional Advisors 0000355437

おすすめ記事