Naming files and running awk

Discussion in 'Mac Programming' started by Bioprogrammer, May 16, 2011.

  1. Bioprogrammer macrumors newbie

    May 16, 2011

    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.

  2. lee1210 macrumors 68040


    Jan 10, 2005
    Dallas, TX
    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?

  3. dmi macrumors regular

    Dec 21, 2010
  4. Bioprogrammer thread starter macrumors newbie

    May 16, 2011

    You guys are awesome. Thanks!
  5. WEBparul macrumors newbie

    May 20, 2011
    Thanks for that , i also need for that.

Share This Page