Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #33034

awk like usage in python

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail
From Rudra Banerjee <bnrj.rudra@gmail.com>
Newsgroups comp.lang.python
Subject awk like usage in python
Date Fri, 09 Nov 2012 16:53:21 +0000
Organization A noiseless patient Spider
Lines 42
Message-ID <1352480001.30761.5.camel@roddur> (permalink)
Mime-Version 1.0
Content-Type text/plain; charset="UTF-8"
Content-Transfer-Encoding quoted-printable
Injection-Info mx04.eternal-september.org; posting-host="490ef412c421f7c80f679c50854ab4bb"; logging-data="7604"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19396WTzws4SJhHcQtUr2K6"
X-Mailer Evolution 3.4.4 (3.4.4-2.fc17)
Cancel-Lock sha1:TmA6moHTOQGZ6U3fP9H66M0Y/SQ=
Xref csiph.com comp.lang.python:33034

Show key headers only | View raw


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?

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

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

csiph-web