linux - AWK or bash profile is adding unwanted color codes to stdout -
linux - AWK or bash profile is adding unwanted color codes to stdout -
hi i'm using awk produce bunch of submissions our cluster.
$ls myfiles* | awk '{for(i=1;i<101;i++){print("qsub -d `pwd` -v file="$1",num="i" -n "$1" run.qsub")}}'
produces -
qsub -d `pwd` -v file=myfiles100.txt,num=100 -n myfiles100.txt run.qsub
except variable $1 (myfiles100.txt) substituted in awk statement, highlighted in greenish syntax. don't know if due bash profile or awk, i've never seen before. problem comes when redirect stdout.
$ls myfiles* | awk '{for(i=1;i<101;i++){print("qsub -d `pwd` -v file="$1",num="i" -n "$1" run.qsub")}}' > somefile.txt
and when open somefile.txt
qsub -d `pwd` -v file=^[[0m^[[32mmyfiles100.txt^[[0m,num=100 -n ^[[0m^[[32myfiles100.txt^[[0m run.qsub
the color codes inserted well, causes confusion when execute these jobs scheduler. can remove color codes nice sed command.
sed -r "s/\x1b\[([0-9]{1,2}(;[0-9]{1,2})?)?[mgk]//g"
but there has setting i'm missing create things easier.
you're not supposed parse output of ls
.
in specific case, it's much improve this:
printf '%s\n' myfiles* | awk '{for(i=1;i<101;i++){print("qsub -d `pwd` -v file="$1",num="i" -n "$1" run.qsub")}}'
here's pure bash possibility accomplish want:
for file in myfiles*; in {1..100}; printf 'qsub -d "$pwd" -v file=%q,num=%d -n %q run.qsub\n' "$file" "$i" "$file" done done > somefile.txt
where used %q
print out filename, in case filename contains spaces or other funny symbols: these quoted (of course, assumes commands executed bash on cluster). used "$pwd"
instead of `pwd`
, you'll save subshell each time command executed.
linux bash shell awk .bash-profile
Comments
Post a Comment