I have scenario where my three huge files Test.txt
, Test1.txt
and Test2.txt
has following details.
H|||||||||||||||||||||||
D||||||||||||||||||||||||
D|||||||||||||||||||||||
H|||||||||||||||||||||
D||||||||||||||||||||||||
D||||||||||||||||||||||||
T||||||||||||||||||||||||
I have to delete all except D lines. It should look like below in all my three files.(more than 10 GB)
D||||||||||||||||||||||||
D|||||||||||||||||||||||
D||||||||||||||||||||||||
D||||||||||||||||||||||||
So after retaining only D's lines in Test.txt
, Test2.txt
and Test3.txt
,
I have to merge those into new file.
I have done the above operation using sed.
sed '/^\('D'\)|/!d' $Filename.txt >> $NewFilename.txt
But because of huge file its taking very long time.
Can we do this operation using any other command in efficient way?
sed -ne /^D/p'
, but by and large, if you don't know any other constraints on your file (fixed line length, for example), your task involves scanning the 10G for '\nD' no matter what.split
on the files. Just be patient, sit out the time (an hour or so?), and do something useful in the meantime. I have script/programs running for hours, days, weeks or even months. I don't wait until they're done :)