Mktemp help please


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Mktemp help please
# 1  
Old 05-30-2013
Mktemp help please

I have the following script


Code:
inp=$input
out=$output
cat_out=$cout
cat_out1=$cout1
cat_outfinal=$coutfinal
echo inp:$inp
echo out:$out
echo cat_out:$cat_out
echo cat_outfinal:$cat_outfinal
awk '{print FNR "\t"$4"\t"$5"\t"$9"\t"$2"\t"$3}' $inp > $out
cat $out | tr "-" " " > $cat_out
cat $cat_out | tr " " "\t" > $cat_out1
awk '{print $1"\t"$2"\t"$3"\t"$4"\t"$5"\t"$6"\t"$7}' $cat_out1 > $cat_outfinal
rm $out
rm $cat_out
rm $cat_out1

inp1=$cat_outfinal
awk '{a=$2;b=$3;c="mod";d="nor";e="bwaSV"}
{if(a-b>0)
         print $1"\t"$3"\t"$2"\t"$4"\t"$5"\t"$6"\t"$7"\t"c"\t"e;
else
        print $0"\t"d"\t"e;
}' $inp1 > $output1

I want to implement mktemp function so that $out,$cat_out and $cat_out1 have unique names.
But I don;t get how to use mktemp.

Can anyone help please.
Thanks

---------- Post updated at 12:38 AM ---------- Previous update was at 12:36 AM ----------

right now I submit the script as


Code:
qsub -v input=/scratch/ccg-ngs/tmp/vishal/results/bwa/svdetect/sample6/3/inversion.txt,output=/scratch/ccg=ngs/tmp/vishal/protext/svdetect/mrsfast/temp12.bed,cout=/scratch/ccg-ngs/tmp/vishal/protext/svdetect/mrsfast/temp22.bed,cout1=/scratch/ccg-ngs/tmp/vishal/protext/svdetect/mrsfast/temp32.bed,coutfinal=/scratch/ccg-ngs/tmp/vishal/protext/svdetect/bwa/int/sample6invy3.bed,output1=/scratch/ccg-ngs/tmp/vishal/protext/svdetect/bwa/inversion/sample6inversion3.bed /scratch/ccg-ngs/tmp/vishal/tst/bedtoolsbwa.sh


Last edited by jim mcnamara; 05-30-2013 at 09:46 PM.. Reason: colour
# 2  
Old 05-30-2013
try

Code:
var1=foo
var2=bar
out=`mktemp  ${var1}XXXX`
cat_out=`mktemp   ${var2}XXXX`

# 3  
Old 05-30-2013
Instead of this:
Code:
awk '{print FNR "\t"$4"\t"$5"\t"$9"\t"$2"\t"$3}' $inp > $out
cat $out | tr "-" " " > $cat_out
cat $cat_out | tr " " "\t" > $cat_out1
awk '{print $1"\t"$2"\t"$3"\t"$4"\t"$5"\t"$6"\t"$7}' $cat_out1 > $cat_outfinal
rm $out
rm $cat_out
rm $cat_out1

Why not use a pipeline like this:
Code:
awk '{print FNR "\t"$4"\t"$5"\t"$9"\t"$2"\t"$3}' $inp |
tr "-" " " | tr " " "\t" |
awk '{print $1"\t"$2"\t"$3"\t"$4"\t"$5"\t"$6"\t"$7}' > $cat_outfinal

Or better still do it all with awk:
Code:
awk '{ gsub("[ -]", "\t"); print FNR, $4, $5, $9, $2, $3, ""}' OFS='\t' $inp > $cat_outfinal

# 4  
Old 05-30-2013
Tried the solution which you suggested
Code:
var1=1a
var2=2b
var3=3c
out='mktemp -p /scratch/ccg-ngs/tmp/vishal/tmp/ ${var1}XXXX || exit1'
cat_out='mktemp -p /scratch/ccg-ngs/tmp/vishal/tmp/ ${var2)XXXX || exit1'
cat_out1='mktemp -p /scratch/ccg-ngs/tmp/vishal/tmp/ ${var3}XXXX || exit1'
cat_outfinal=$coutfinal

and then:
Code:
awk '{print FNR "\t"$4"\t"$5"\t"$9"\t"$2"\t"$3}' $inp > $out
cat $out | tr "-" " " > $cat_out
cat $cat_out | tr " " "\t" > $cat_out1
awk '{print $1"\t"$2"\t"$3"\t"$4"\t"$5"\t"$6"\t"$7}' $cat_out1 > $cat_outfinal


But it throws these kind of errors

Code:
/var/spool/torque/mom_priv/jobs/1109180.SC: line 32: $out: ambiguous redirect
cat: invalid option -- p
Try `cat --help' for more information.
/var/spool/torque/mom_priv/jobs/1109180.SC: line 33: $cat_out: ambiguous redirect
/var/spool/torque/mom_priv/jobs/1109180.SC: line 34: $cat_out1: ambiguous redirect
cat: invalid option -- p
Try `cat --help' for more information.
awk: cmd. line:1: fatal: cannot open file `mktemp' for reading (No such file or directory)

---------- Post updated at 01:23 AM ---------- Previous update was at 01:21 AM ----------

used without || exit1 as well

---------- Post updated at 01:33 AM ---------- Previous update was at 01:23 AM ----------

HI Chubler_XL

Thanks a lot for your help. Great. I wanted something like that.
New to scripting so don't have any idea to use pipe proprtly. I must learn it.

Thanks a lot again for the help.
Wonderful

Last edited by Franklin52; 05-31-2013 at 03:18 AM.. Reason: Please use code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

2 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Edit mktemp file

If I create this random named file, how would I edit it within the script with say Geany? mktemp XXXXXXXX.txt (1 Reply)
Discussion started by: drew77
1 Replies

2. UNIX for Advanced & Expert Users

mktemp error

When I execute a korn shell script , I am getting the following error. "mktemp not found" Why I am getting this...is this error related to script. (6 Replies)
Discussion started by: tkbharani
6 Replies
Login or Register to Ask a Question