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?
Best Answer
Or:
Or if your
grep
like GNUgrep
supports the-h
option (to avoid printing file names):By using
LC_ALL=C
we avoidgrep
trying to parse UTF-8 data. By using^D
,grep
will only look at the first character of each line.grep
, especially GNUgrep
is generally a lot faster thansed
.