Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #33034 > unrolled thread
| Started by | Rudra Banerjee <bnrj.rudra@gmail.com> |
|---|---|
| First post | 2012-11-09 16:53 +0000 |
| Last post | 2012-11-09 23:50 -0800 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
awk like usage in python Rudra Banerjee <bnrj.rudra@gmail.com> - 2012-11-09 16:53 +0000
Re: awk like usage in python Tim Roberts <timr@probo.com> - 2012-11-09 23:50 -0800
| From | Rudra Banerjee <bnrj.rudra@gmail.com> |
|---|---|
| Date | 2012-11-09 16:53 +0000 |
| Subject | awk like usage in python |
| Message-ID | <1352480001.30761.5.camel@roddur> |
Friends,
I am in process learning python.
I basically use shell scripts for text formatting and trying my hand on
python.
where I am fighting is awk's functionality in python.
Say, one of my real tiny code looks like:
#!/bin/bash
TMP=store
for i in $1/MnBi_EOS_*
do
# echo $i
grep -A 15 "T(est)" $i/out-Dy-eos2 >$TMP
var_T=`awk '/T\(est\)/{printf $2}' $TMP`
var_s1=`awk '/s1,torque/{print $6;exit}' $TMP`
var_t=`awk '/s1,torque/{print $7;exit}' $TMP`
echo $var_T $var_s1 $var_t >>tfl
# echo ""
# echo ""
done
sort -n tfl >$2
rm -i $TMP tfl
where the store looks like:
T(est)= 266.58K
TOTDOS= 0.48669E+02n_Ef= 0.62856E+02 Ebnd-0.11707E+02
spec,subl= 1 1N= 0.72132E+01s1c=-0.50284E+00
spec,subl= 1 1 lined-up= 0.99999E+00
species,subl,cmp= 1 1 1 s1,torque= 0.59382E-02 0.36773E-04
species,sublat,cmp= 1 1 1 sp-mom= 0.14449E+01
species,sublat,cmp= 1 1 1 orbmom= 0.41075E-01
species,subl,cmp= 1 1 2 s1,torque=-0.33939E-12 0.20885E-12
species,sublat,cmp= 1 1 2 sp-mom= 0.54080E+00
species,sublat,cmp= 1 1 2 orbmom= 0.14921E-01
species,subl,cmp= 1 1 3 s1,torque= 0.60002E-02 0.15728E-02
species,sublat,cmp= 1 1 3 sp-mom= 0.14448E+01
species,sublat,cmp= 1 1 3 orbmom= 0.43989E-01
spec,subl= 1 2N= 0.72132E+01s1c=-0.50284E+00
spec,subl= 1 2 lined-up= 0.99999E+00
species,subl,cmp= 1 2 1 s1,torque= 0.59378E-02 0.36850E-04
How can I import the awk functionality in python?
[toc] | [next] | [standalone]
| From | Tim Roberts <timr@probo.com> |
|---|---|
| Date | 2012-11-09 23:50 -0800 |
| Message-ID | <ug1s98dgks6biabvlq00edf7ktvr9amb6j@4ax.com> |
| In reply to | #33034 |
Rudra Banerjee <bnrj.rudra@gmail.com> wrote:
>
>Friends,
>I am in process learning python.
>I basically use shell scripts for text formatting and trying my hand on
>python.
>where I am fighting is awk's functionality in python.
>Say, one of my real tiny code looks like:
>#!/bin/bash
>TMP=store
>for i in $1/MnBi_EOS_*
>do
># echo $i
> grep -A 15 "T(est)" $i/out-Dy-eos2 >$TMP
> var_T=`awk '/T\(est\)/{printf $2}' $TMP`
> var_s1=`awk '/s1,torque/{print $6;exit}' $TMP`
> var_t=`awk '/s1,torque/{print $7;exit}' $TMP`
> echo $var_T $var_s1 $var_t >>tfl
># echo ""
># echo ""
>done
>sort -n tfl >$2
>rm -i $TMP tfl
Well, describe your program in words. Then, you can convert it to Python.
For every directory in the given directory whose name starts with
MnBi_EOS_:
extract the 15 lines starting with T(est) from the file out-Dy-eos2 to
a temporary file
extract the 2nd field from the line with T(est) in it
extract the 6th field from the first line with "s1,torque"
extract the 7th field from the first line with "s1,torque"
print those three fields to a file
sort that file
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web