Issue
I am parsing a text file with a grep command in bash. I would like to print the output in another txt file. I am using this line:
grep 'ACCESSION' chrom_CDS_2.txt | awk '{print $0'\n'}' > accession_out.txt
The result in the accession_out.txt is like this:
Instead if I open accession_out.txt in Microsoft Word I have the result that I have tried to format with my bash command:
ACCESSION AC087816
ACCESSION AC091485
ACCESSION AC092153
ACCESSION AC092156
ACCESSION AC092159
ACCESSION AC092165
ACCESSION AC092176
ACCESSION AC092178
ACCESSION AC092206
ACCESSION AC092431
ACCESSION AC092455
ACCESSION AC092461
ACCESSION AC092533 AC027148
ACCESSION AC092567 AC040931
ACCESSION AC092569 AC068689
ACCESSION AC092570 AC060792
ACCESSION AC092573 AC015764
ACCESSION AC092575 AC018378
ACCESSION AC092587 AC023965
ACCESSION AC092598 AC027781
ACCESSION AC092603 AC073396
Could someone please explain to me how can I obtain the same visualization of Word editor in Notepad?
Seems that Notepad disregard the '\n' tag.
Thank you.
Solution
Using awk
for fixing the problem is an idea, after some adjustments.
You need \r
(the Windows linefeed) and use double quotes.
grep 'ACCESSION' chrom_CDS_2.txt | awk '{print $0 "\r"}' > accession_out.txt
When you use awk
, you do not need grep
:
awk '/ACCESSION/ {print $0 "\r"}' chrom_CDS_2.txt > accession_out.txt
Another possibility is using sed
: By default don't print lines. When ACCESSION
is part of the line, replace the complete line with the complete line (&
, matched part), followed by \r
and use /p
for printing it.
sed -n 's/.*ACCESSION.*/&\r/p' chrom_CDS_2.txt > accession_out.txt
Answered By - Walter A Answer Checked By - Mildred Charles (WPSolving Admin)