PDA

View Full Version : Naming files and running awk




Bioprogrammer
May 16, 2011, 09:40 PM
Hi,

I'm new to programming. I've written some scripts in awk and want to make a batch file or program to run these scripts reading one file and naming new files depending on the scripts that were used.

These are 2 examples of different scripts I'm using.
awk '{if($2 == 64 || $2 ==128){print $0}}' filein.sam > fileout64or129.sam
awk '{if($2 == 65 || $2 ==129){print $0}}' filein.sam > fileout65or129.sam

This is the file I made today and it is running one the awk script (I can see it in top), but doesn't seem to create a file I can find. (This file doesn't include the second awk script, I seem to have a problem naming the files rather than running the program or awk commands)

echo Enter file name
read NAME
awk '{if($2 == 65 || $2 ==129){print $0}}' $NAME > $NAME65or129.sam


What I would like to do is be able to type in the name of the file (filein.sam), have it run both scripts and name the output files fileout64or129.sam, fileout65or129.sam, or fileout(some flag).sam.

Thanks



lee1210
May 16, 2011, 11:07 PM
I'm not totally sure what you want to do or what problem you're currently having. Is the awk piece working properly but your shell script is not? Do you want to strip .sam before naming your output file?

-Lee

dmi
May 17, 2011, 09:03 AM
${NAME}65or129.sam

Bioprogrammer
May 19, 2011, 11:12 AM
${NAME}65or129.sam

You guys are awesome. Thanks!

WEBparul
May 20, 2011, 07:56 AM
${NAME}65or129.sam
Thanks for that , i also need for that.