开发者

deleting brackets in a file using sed

Can anyone help me in deleting brackets in a file ? here is my script ..

  #!/bin/bash

for file in fftw is_c mpi_tile pmb tau xhpl
do
    for state in C0 C1 C2 C4
    do
    printf "${file}_${state}_v1.xls"

    sed -e 's/\(//'开发者_如何学Go ${file}_${state}_v1.xls
    sed -e 's/\)//' ${file}_${state}_v1.xls

    awk '{sum+=$3} ; END {print "  ", sum/NR}' ${file}_${state}_v1.xls >> c-state-residency.xls
    done
done


Short answer: use --in-place with sed to do what you think you're doing.

You're deleting parenthesis, not brackets, and only the first one on each line (or you would be if you removed the \ you don't need). This also seems like an odd thing to do to an Excel spreadsheet.

You probably want to pipe the output of the sed commands to awk instead of modifying the files in place though...


I would use tr -d ..., like so:

$ echo "(this is my string)" | tr -d '()' 
this is my string


Found solution for deleting special characters

#!/bin/bash

for file in fftw is_c mpi_tile pmb tau xhpl
do
    for state in C0 C1 C2 C4
    do
    printf "${file}_${state}_v1.xls"
    sed -e 's/[()]//g' ${file}_${state}_v1.xls
    awk '{sum+=$3} ; END {print "Average C-state residency  ", sum/NR}' ${file}_${state}_v1.xls >> c-state-residency.xls
    done
done


instead of using sed, it seems simpler to just use "tr" to replace the characters with nothing

 cat ${file}_${state}_v1.xls | tr '(' '' | tr ')' '' > ${file}_${state}_v1.xls
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜