How to remove a break line \n in awk when print the result
Dear all,
I have an inputfile.txt which contains the following:
ftp://ftp.ncbi.nlm.nih.gov/genomes/all/GCF/000/248/415/GCF_000248415.2_ASM24841v2
ftp://ftp.ncbi.nlm.nih.gov/genomes/all/GCF/001/011/135/GCF_001011135.1_ASM101113v1
..
..
..
I used the command which purpose is to download genome assemblies from NCBI website
awk 'BEGIN{FS=OFS="/";filesuffix="genomic.fna.gz"}{ftpdir=$0;asm=$10;file=asm"_"filesuffix;print "wget "ftpdir,file}' inputfile.txt > outputfile.sh
The problem is that it generates a string with break lines like this:
wget ftp://ftp.ncbi.nlm.nih.gov/genomes/all/GCF/000/248/415/GCF_000248415.2_ASM24841v2
/GCF_000248415.2_ASM24841v2
_genomic.fna.gz
And I want it to be one line like this:
wget_ftp://ftp.ncbi.nlm.nih.gov/genomes/all/GCF/000/248/415/GCF_000248415.2_ASM24841v2/GCF_000248415.2_ASM24841v2_genomic.fna.gz
How can I achieve it?
Thanks!
• 1,071 views
•
link
2 answers
awk -F '/' '{printf("%s/%s_genomic.fna.gz\n",$0,$NF);}' input.txt > urls.txt
and then
wget --input-file=urls.txt
• 0 views
•
link
$ perl -pe 's/\n/, /' inputfile.txt
$ tr '\n' ',' < inputfile.txt
• 0 views
•
link
Log in to answer this question.