Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Awk > Re: manipulatin...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 7 of 9 Topic 2160 of 2236
Post > Topic >>

Re: manipulating texts

by Minalba Jordao <minalbajordao@[EMAIL PROTECTED] > Feb 12, 2008 at 06:18 AM

On 12 fev, 11:33, Ed Morton <mor...@[EMAIL PROTECTED]
> wrote:
> On 2/12/2008 7:23 AM, Minalba Jordao wrote:
>
>
>
> > On 12 fev, 11:15, Ed Morton <mor...@[EMAIL PROTECTED]
> wrote:
>
> >>On 2/12/2008 6:57 AM, Minalba Jordao wrote:
>
> >>>Hello!
>
> >>>I am a newbie.
>
> >>>I have a few problems.
>
> >>>I have a file that looks like:
> >>>"
> >>>! comments
> >>>! comments
> >>>! comments
>
> >>>@[EMAIL PROTECTED]
 text
> >>>X
> >>>Y
> >>>Z
> >>>@[EMAIL PROTECTED]
>
> >>>column1 column2 column3 column4
> >>>column1 column2 column3 column4
> >>>... ... ...
> >>>... ... ...
> >>>column1 column2 column3 column4
> >>>column1 column2 column3 column4
> >>>"
>
> >>>My questions:
> >>>I would to get the
> >>>- "! coments"
> >>>- what is between the @[EMAIL PROTECTED]
 (at sign).
> >>>and
> >>>column1 column2 -column3
> >>>for each line..
>
> >>>could anyone help me?
>
> >>>Mina
>
> >>This MAY be what you want, but it's not clear:
>
> >>awk '
> >>/^@[EMAIL PROTECTED]
 { a=!a; b=1; next }
> >>a || /^!/ { print; next }
> >>b { print $1,$2,$3 }
> >>' file
>
> >>If not, post some sample input and expected output.
>
> >>        Ed.
>
> > that worked!
> > But it did`t include the @[EMAIL PROTECTED]
 sign.
> > ' comments
> > ! comments
> > ! comments
> > !
> >  X
> >  Y
> >  Z
> > 1865.16833 6639.33984 -3278.68018
> > 1865.21423 6539.07471 -3284.02954
> > 1889.54529 6414.59814 -3287.10986
>
> > and it should be like
> > ' comments
> > ! comments
> > ! comments
> > !
> > @[EMAIL PROTECTED]
> >  X
> >  Y
> >  Z
> > @[EMAIL PROTECTED]
> > 1865.16833 6639.33984 -3278.68018
> > 1865.21423 6539.07471 -3284.02954
> > 1889.54529 6414.59814 -3287.10986
>
> See my other post in this thread after you'd clarified that requirement
in a
> followup to your original post.
>
>         Ed.

Ed,
It did work. Thank you.
But I didn`t understand acctually what you did.

In the first line, you look for the @[EMAIL PROTECTED]
 sign in the begining of of the
line, then you print what you search. OK, then a=!a and b=1, I didn`t
understand what does this means.
/^@[EMAIL PROTECTED]
 { print; a=!a; b=1; next }
a || /^!/ { print; next }
b { print $1,$2,"-"$3 }

What can I read to understand it better?
Thank you again.

If I need to to that, with many files? Could I do it with awk? Or will
I need to use some shell scripting?

$
for file in *.dat; do ./trans.sh $file > $file.new; done

transf.sh
#!/bin/sh
awk ' /^@[EMAIL PROTECTED]
 { print; a=!a; b=1; next }
      a || /^!/ { print; next }
      b { print $1,$2,"-"$3 }' $1


Any suggestions?




 9 Posts in Topic:
manipulating texts
Minalba Jordao <minalb  2008-02-12 04:57:31 
Re: manipulating texts
Minalba Jordao <minalb  2008-02-12 05:08:17 
Re: manipulating texts
Ed Morton <morton@[EMA  2008-02-12 07:18:19 
Re: manipulating texts
Ed Morton <morton@[EMA  2008-02-12 07:15:37 
Re: manipulating texts
Minalba Jordao <minalb  2008-02-12 05:23:03 
Re: manipulating texts
Ed Morton <morton@[EMA  2008-02-12 07:33:05 
Re: manipulating texts
Minalba Jordao <minalb  2008-02-12 06:18:06 
Re: manipulating texts
Ed Morton <morton@[EMA  2008-02-12 08:48:22 
Re: manipulating texts
Ed Morton <morton@[EMA  2008-02-12 08:52:37 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri May 16 23:06:34 CDT 2008.