Skip to main content
added 2 characters in body
Source Link
user10345633
  • 413
  • 1
  • 3
  • 14

Related to my previous question....

I want to get a line where the first column has a certain string from 5000 files. But I want to show the lines in the output file by the order of input files. For example,

File_1

agd fkg fls  ofk
ggs kkg ikg  gkl
bsg ksf olg  lzj
many more lines,,,
kgf kkg ikg  lgk

File_2

gik zlg olg  pzk
ppl sjg gol  dzj
zjg iwj bmh  hgi
many more lines,,,
kgf wlg ugk  lkf
many more files...

many more files...

Output_file

kgf kkg ikg lgk  -- This line from the File_1
kgf wlg ugk lkf  -- This is from the File_2
more lines...
kgf ald fig wdg  -- This last line is from the File_5000 

Just getting a line from multiple files can be as below.

grep -rEh `kgf` File_* > Output_file

But if I do this, output_file shows lines in the random order. The first line of the Output file can be from File_20 or others, and not the File_1. So I want the output_file to show the line from File_1 in the first line of output file, File_2 to be the 2nd line of output file, File_3 to be the 3rd of output file, etc.

Does anybody know this?

Thank you in advance!

Related to my previous question....

I want to get a line where the first column has a certain string from 5000 files. But I want to show the lines in the output file by the order of input files. For example,

File_1

agd fkg fls  ofk
ggs kkg ikg  gkl
bsg ksf olg  lzj
many more lines,,,
kgf kkg ikg  lgk

File_2

gik zlg olg  pzk
ppl sjg gol  dzj
zjg iwj bmh  hgi
many more lines,,,
kgf wlg ugk  lkf
many more files...

Output_file

kgf kkg ikg lgk  -- This line from the File_1
kgf wlg ugk lkf  -- This is from the File_2
more lines...
kgf ald fig wdg  -- This last line is from the File_5000 

Just getting a line from multiple files can be as below.

grep -rEh `kgf` File_* > Output_file

But if I do this, output_file shows lines in the random order. The first line of the Output file can be from File_20 or others, and not the File_1. So I want the output_file to show the line from File_1 in the first line of output file, File_2 to be the 2nd line of output file, File_3 to be the 3rd of output file, etc.

Does anybody know this?

Thank you in advance!

Related to my previous question....

I want to get a line where the first column has a certain string from 5000 files. But I want to show the lines in the output file by the order of input files. For example,

File_1

agd fkg fls  ofk
ggs kkg ikg  gkl
bsg ksf olg  lzj
many more lines,,,
kgf kkg ikg  lgk

File_2

gik zlg olg  pzk
ppl sjg gol  dzj
zjg iwj bmh  hgi
many more lines,,,
kgf wlg ugk  lkf

many more files...

Output_file

kgf kkg ikg lgk  -- This line from the File_1
kgf wlg ugk lkf  -- This is from the File_2
more lines...
kgf ald fig wdg  -- This last line is from the File_5000 

Just getting a line from multiple files can be as below.

grep -rEh `kgf` File_* > Output_file

But if I do this, output_file shows lines in the random order. The first line of the Output file can be from File_20 or others, and not the File_1. So I want the output_file to show the line from File_1 in the first line of output file, File_2 to be the 2nd line of output file, File_3 to be the 3rd of output file, etc.

Does anybody know this?

Thank you in advance!

Source Link
user10345633
  • 413
  • 1
  • 3
  • 14

How to get a line with a string from multiple files by file orders?

Related to my previous question....

I want to get a line where the first column has a certain string from 5000 files. But I want to show the lines in the output file by the order of input files. For example,

File_1

agd fkg fls  ofk
ggs kkg ikg  gkl
bsg ksf olg  lzj
many more lines,,,
kgf kkg ikg  lgk

File_2

gik zlg olg  pzk
ppl sjg gol  dzj
zjg iwj bmh  hgi
many more lines,,,
kgf wlg ugk  lkf
many more files...

Output_file

kgf kkg ikg lgk  -- This line from the File_1
kgf wlg ugk lkf  -- This is from the File_2
more lines...
kgf ald fig wdg  -- This last line is from the File_5000 

Just getting a line from multiple files can be as below.

grep -rEh `kgf` File_* > Output_file

But if I do this, output_file shows lines in the random order. The first line of the Output file can be from File_20 or others, and not the File_1. So I want the output_file to show the line from File_1 in the first line of output file, File_2 to be the 2nd line of output file, File_3 to be the 3rd of output file, etc.

Does anybody know this?

Thank you in advance!