shell - How do I write an awk print command in a loop? -


i write loop creating various output files first column of each input file, respectively.

so wrote

for in $(\ls -d /home/*paired.isoforms.results) awk -f"\t" {print $1}' $i > $i.transcript_ids.txt done 

as example if there 5 files in home directory named

a_paired.isoforms.results b_paired.isoforms.results c_paired.isoforms.results d_paired.isoforms.results e_paired.isoforms.results 

i print first column of each of these files seperate output file, i.e. have 5 output files called

a.transcript_ids.txt b.transcript_ids.txt c.transcript_ids.txt d.transcript_ids.txt e.transcript_ids.txt 

or other name long 5 different names , can still link them original files.

i understand, there problem double usage of $ in both awk , loop command, don't know how change that.

is possible write command in loop?

this should job:

for file in /home/*paired.isoforms.results     base=${file##*/}     base=${base%%_*}     awk -f"\t" '{print $1}' $file > $base.transcript_ids.txt done 

i assume there can spaces in first field since set delimiter explicitly tab. runs awk once per file. there ways running awk once files, i'm not convinced benefit significant. consider using cut instead of awk '{print $1}', too. note using ls did less satisfactory using globbing directly; runs foul of file names oddball characters (spaces, tabs, etc) in name.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -