Search code examples
awksequencefastagnu-parallel

How can I use awk (first field of each file) on multiple files and get the result for each input file


I've tried ls *.fasta | parallel --gnu "awk '{print $1}' > {/.}.outputfile.txt" and its not producing the result I need. I have 48 files where I need to extract these fields and output them to 48 independent files.

I can run this just fine but I have to do it for each file one by one: awk '{print $1}' BLAST_output_file.txt > ID_ BLAST_output_file.txt

Can someone help me out here? Thanks


Solution

  • Could you please try following.

    awk '{if(FILENAME!=prev){close(prev)};print $1;prev=FILENAME}'  *.fasta > output_all_file
    

    In case you need to have different output file(saw from your attempt):

    awk '{if(FILENAME!=prev){close(prev)};print $1 > (FILENAME".id.blast.out.txt");prev=FILENAME}'  *.fasta