all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Easy for Some
@ 2010-01-04 10:25 ` marioepsley
  2010-01-04 16:28   ` Vicente Hernando Ara
                     ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: marioepsley @ 2010-01-04 10:25 UTC (permalink / raw
  To: Help-gnu-emacs


I'm not coder but i needed to extract some information from a text file and
some one pointed me in this direction. 

I have a file like this, could have up to a 1000 keyframes.:



Effects   Sound Keys #1   Output 1 #22
   Frame
   0   0.17489
   1   0.261281
   2   0.361762
   3   0.400085
   4   0.411538
   5   0.434799
   6   0.41712
   7   0.422151
   8   0.43181
   9   0.411811

Just to clarify the spacings: (     0       0.17489    )
Just to clarify the spacings: (tab0tab 0.17489 tab)

and i want to be left with just the raw values like this:


0.17489
0.261281
0.361762
0.400085
0.411538
0.434799
0.41712
0.422151
0.43181
0.411811


I am a complete newbie, i downloaded aquamacs emacs yesterday, tried to use
replace string as a guess...?? no joy. Dont have anyone to ask, any help is
greatly appreciated.
-- 
View this message in context: http://old.nabble.com/Easy-for-Some-tp27011067p27011067.html
Sent from the Emacs - Help mailing list archive at Nabble.com.





^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Easy for Some
  2010-01-04 10:25 ` Easy for Some marioepsley
@ 2010-01-04 16:28   ` Vicente Hernando Ara
  2010-01-04 17:45   ` Peter Dyballa
                     ` (3 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: Vicente Hernando Ara @ 2010-01-04 16:28 UTC (permalink / raw
  To: marioepsley; +Cc: Help-gnu-emacs

An easy way, without coding any function is using rectangles.

* You open the keyframe file.
* Put the pointer in the first 0 of 0.xxxx  number.
* Set the mark with: C-space.
* Go to the last number of the last keyframe. E.g: 0.411811 last 1
* Now kill the rectangle: C-x r k
* Create the new file where you want to save the data, and open it.
* Yank the rectangle: C-x r y
* Save the file.

It is done. :-)





On 04/01/2010, marioepsley <marioepsley@aol.com> wrote:
>
> I'm not coder but i needed to extract some information from a text file and
> some one pointed me in this direction.
>
> I have a file like this, could have up to a 1000 keyframes.:
>
>
>
> Effects   Sound Keys #1   Output 1 #22
>    Frame
>    0   0.17489
>    1   0.261281
>    2   0.361762
>    3   0.400085
>    4   0.411538
>    5   0.434799
>    6   0.41712
>    7   0.422151
>    8   0.43181
>    9   0.411811
>
> Just to clarify the spacings: (     0       0.17489    )
> Just to clarify the spacings: (tab0tab 0.17489 tab)
>
> and i want to be left with just the raw values like this:
>
>
> 0.17489
> 0.261281
> 0.361762
> 0.400085
> 0.411538
> 0.434799
> 0.41712
> 0.422151
> 0.43181
> 0.411811
>
>
> I am a complete newbie, i downloaded aquamacs emacs yesterday, tried to use
> replace string as a guess...?? no joy. Dont have anyone to ask, any help is
> greatly appreciated.
> --
> View this message in context:
> http://old.nabble.com/Easy-for-Some-tp27011067p27011067.html
> Sent from the Emacs - Help mailing list archive at Nabble.com.
>
>
>
>




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Easy for Some
  2010-01-04 10:25 ` Easy for Some marioepsley
  2010-01-04 16:28   ` Vicente Hernando Ara
@ 2010-01-04 17:45   ` Peter Dyballa
  2010-01-05  2:23     ` Kevin Rodgers
  2010-01-04 20:40   ` Andreas Politz
                     ` (2 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Peter Dyballa @ 2010-01-04 17:45 UTC (permalink / raw
  To: marioepsley; +Cc: Help-gnu-emacs


Am 04.01.2010 um 11:25 schrieb marioepsley:

> I am a complete newbie, i downloaded aquamacs emacs yesterday, tried  
> to use
> replace string as a guess


You could use awk to print only the second column, i.e., the second by  
white space separated word of each line, when it exists in this  
record. Then it would also output the second word of the header lines  
which you'd need to filter:

	awk '{if (NF > 1) print $2}' <file name> | egrep -v '[^-0-9.]'

--
Greetings

   Pete

"Klingons do not believe in indentation - except perhaps in the skulls  
of their project managers."





^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Easy for Some
  2010-01-04 10:25 ` Easy for Some marioepsley
  2010-01-04 16:28   ` Vicente Hernando Ara
  2010-01-04 17:45   ` Peter Dyballa
@ 2010-01-04 20:40   ` Andreas Politz
  2010-01-05  2:44   ` Steve Revilak
  2010-01-05 15:40   ` Memnon Anon
  4 siblings, 0 replies; 10+ messages in thread
From: Andreas Politz @ 2010-01-04 20:40 UTC (permalink / raw
  To: help-gnu-emacs

marioepsley <marioepsley@aol.com> writes:

> I'm not coder but i needed to extract some information from a text file and
> some one pointed me in this direction. 
>
> I have a file like this, could have up to a 1000 keyframes.:
>
>
>
> Effects   Sound Keys #1   Output 1 #22
>    Frame
>    0   0.17489
>    1   0.261281
>    2   0.361762
>    3   0.400085
>    4   0.411538
>    5   0.434799
>    6   0.41712
>    7   0.422151
>    8   0.43181
>    9   0.411811
>
> Just to clarify the spacings: (     0       0.17489    )
> Just to clarify the spacings: (tab0tab 0.17489 tab)
>
> and i want to be left with just the raw values like this:
>
>
> 0.17489
> 0.261281
> 0.361762
> 0.400085
> 0.411538
> 0.434799
> 0.41712
> 0.422151
> 0.43181
> 0.411811
>
>
> I am a complete newbie, i downloaded aquamacs emacs yesterday, tried to use
> replace string as a guess...?? no joy. Dont have anyone to ask, any help is
> greatly appreciated.

There are many ways to solve this (See the other replies.).  Most of
them use regular expressions in one way or another.

First move to the beginning of your file and get rid of the lines you
don't want.  (All based on your example data.  'RET' means 'return/enter
key', 'M-<' means press Alt/Meta + '<', 'M-x' likewise.)

M-<
M-x keep-lines RET ^\s-*[0-9]+\s-+[0-9]+\(\.[0-9]+\)?\s-*$ RET

Back to the beginning.
M-<

Now, on every line, replace everything with the decimal number. 

M-x replace-regexp RET ^\s-*[0-9]+\s-+\([0-9]+\(\.[0-9]+\)?\)\s-*$ RET \1 RET

I hope this works.

-ap





^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Easy for Some
  2010-01-04 17:45   ` Peter Dyballa
@ 2010-01-05  2:23     ` Kevin Rodgers
  0 siblings, 0 replies; 10+ messages in thread
From: Kevin Rodgers @ 2010-01-05  2:23 UTC (permalink / raw
  To: help-gnu-emacs

Peter Dyballa wrote:
> 
> Am 04.01.2010 um 11:25 schrieb marioepsley:
> 
>> I am a complete newbie, i downloaded aquamacs emacs yesterday, tried 
>> to use
>> replace string as a guess
> 
> 
> You could use awk to print only the second column, i.e., the second by 
> white space separated word of each line, when it exists in this record. 
> Then it would also output the second word of the header lines which 
> you'd need to filter:
> 
>     awk '{if (NF > 1) print $2}' <file name> | egrep -v '[^-0-9.]'

You (almost) never need to pipe awk's output through (e)grep:

awk 'NF == 2 && $2 ~ /^[0-9]+\.[0-9]+$/ {print $2}' FILE

-- 
Kevin Rodgers
Denver, Colorado, USA





^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Easy for Some
  2010-01-04 10:25 ` Easy for Some marioepsley
                     ` (2 preceding siblings ...)
  2010-01-04 20:40   ` Andreas Politz
@ 2010-01-05  2:44   ` Steve Revilak
  2010-01-05 15:40   ` Memnon Anon
  4 siblings, 0 replies; 10+ messages in thread
From: Steve Revilak @ 2010-01-05  2:44 UTC (permalink / raw
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 1365 bytes --]

>From: marioepsley <marioepsley@aol.com>

>I have a file like this, could have up to a 1000 keyframes.:
>
>Effects   Sound Keys #1   Output 1 #22
>   Frame
>   0   0.17489
>   1   0.261281
>   2   0.361762
>   3   0.400085
>   4   0.411538
>   5   0.434799
>   6   0.41712
>   7   0.422151
>   8   0.43181
>   9   0.411811
>
>Just to clarify the spacings: (     0       0.17489    )
>Just to clarify the spacings: (tab0tab 0.17489 tab)
>
>and i want to be left with just the raw values like this:
>
>
>0.17489
>0.261281
>0.361762
>0.400085
>0.411538
>0.434799
>0.41712
>0.422151
>0.43181
>0.411811


This isn't really an emacs answer, but

   cut -f3 foo.txt

should do what you want (assuming that your data is in a file called
"foo.txt").


>I am a complete newbie, i downloaded aquamacs emacs yesterday

Since you mentioned aquamacs, I'm going to guess that you're using a
Mac.  If so, you'll need to run `cut' from within Terminal.app.

Of, if you want to do it within emacs, open the file with emacs and try

   C-x h ESC 1 ESC | cut -f3 RET

Broken down, this is

   C-x h       ;; selects entire buffer

   ESC 1 ESC | ;; ESC | pipes region to a command.  ESC 1 is
               ;; a prefix argument that means "replace the region
               ;; with the output of the command"

   cut -f3 RET ;; This is the command you're running on the region


Steve

[-- Attachment #2: Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Easy for Some
       [not found] <mailman.707.1262616303.18930.help-gnu-emacs@gnu.org>
@ 2010-01-05 10:01 ` Anselm Helbig
  2010-01-05 21:54 ` Colin S. Miller
  1 sibling, 0 replies; 10+ messages in thread
From: Anselm Helbig @ 2010-01-05 10:01 UTC (permalink / raw
  To: help-gnu-emacs

Hi!

> I'm not coder but i needed to extract some information from a text file and
> some one pointed me in this direction. 
> 
> I have a file like this, could have up to a 1000 keyframes.:
> 
> 
> 
> Effects   Sound Keys #1   Output 1 #22
>    Frame
>    0   0.17489
>    1   0.261281
>    2   0.361762
>    3   0.400085
>    4   0.411538
>    5   0.434799
>    6   0.41712
>    7   0.422151
>    8   0.43181
>    9   0.411811
> 
> Just to clarify the spacings: (     0       0.17489    )
> Just to clarify the spacings: (tab0tab 0.17489 tab)
> 
> and i want to be left with just the raw values like this:
> 
> 
> 0.17489
> 0.261281
> 0.361762
> 0.400085
> 0.411538
> 0.434799
> 0.41712
> 0.422151
> 0.43181
> 0.411811
> 
> 
> I am a complete newbie, i downloaded aquamacs emacs yesterday, tried to use
> replace string as a guess...?? no joy. Dont have anyone to ask, any help is
> greatly appreciated.

There are three obvious ways to achieve this: 

1. use regular expressions

   if it is sufficient to get rid of the leading whitespace and number:

     M-x query-replace-regexp RET ^\s-*[0-9]+\s-* RET RET

   If you need to get rid of trailing whitespace as well:

     M-x query-replace-regexp RET ^\s-*[0-9]+\s-*\([.0-9]+\)\s-*$ RET \1 RET

   Don't be afraid, regular expressions are easier to write than to
   read. Regular expressions are the tool of choice if you want to
   touch only lines matching a pattern.

2. with keyboard macros

   Go to start of the first line, press `C-x (' to start your keyboard
   macro and do whatever you need to clean up one line and go to the
   start of the next line, end your keyboard macro with `C-x )'. 
   Repeat your keyboard macro by giving a big prefix to C-x e,
   e.g. `C-u 1000 C-x e'. It will stop when it reaches the end of the
   file. 

   Keyboard macros are superior if you need to do some more complex
   manipulations on your text, but they can easily break unless your
   text structure is very rigid. They can also be a bit slow if you
   need to go through a big file. Also, of course, it's easy to
   understand how a keyboard macro works than to grok regular
   expressions. 

3. use rectangle functions

   place your cursor at the start of the first line and set the mark
   with `C-SPACE'. Go to the end of the file on the last line so that
   the cursor (`point' in emacs lingo) is on the first column you want
   to keep. Delete the rectangular portion of the buffer with 
   `C-x r k'.

HTH, 

Anselm


-- 
Anselm Helbig - http://mnemonikk.org/


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Easy for Some
  2010-01-04 10:25 ` Easy for Some marioepsley
                     ` (3 preceding siblings ...)
  2010-01-05  2:44   ` Steve Revilak
@ 2010-01-05 15:40   ` Memnon Anon
  2010-01-05 17:33     ` Memnon Anon
  4 siblings, 1 reply; 10+ messages in thread
From: Memnon Anon @ 2010-01-05 15:40 UTC (permalink / raw
  To: help-gnu-emacs

marioepsley <marioepsley@aol.com> writes:

> I have a file like this, could have up to a 1000 keyframes.:
[...]
> Effects   Sound Keys #1   Output 1 #22
>    Frame
>    0   0.17489
>    1   0.261281
>    2   0.361762
[...]
> and i want to be left with just the raw values like this:
>
> 0.17489
> 0.261281
> 0.361762
[...]
> I am a complete newbie, i downloaded aquamacs emacs yesterday, tried to use
> replace string as a guess...?? no joy. Dont have anyone to ask, any help is
> greatly appreciated.

I am no programmer, too; I think I would go with emacs keyboard macros.
You do not need any extra tools or special programing knowledger:
Just the basic emacs commands.

See this:
,----[ (info "(emacs)Keyboard Macros") ]
|    You define a keyboard macro by executing and recording the commands
| which are its definition.  Put differently, as you define a keyboard
| macro, the definition is being executed for the first time.  This way,
| you can see the effects of your commands, so that you don't have to
| figure them out in your head.  When you close the definition, the
| keyboard macro is defined and also has been, in effect, executed once.
| You can then do the whole thing over again by invoking the macro.
`----

hth





^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Easy for Some
  2010-01-05 15:40   ` Memnon Anon
@ 2010-01-05 17:33     ` Memnon Anon
  0 siblings, 0 replies; 10+ messages in thread
From: Memnon Anon @ 2010-01-05 17:33 UTC (permalink / raw
  To: help-gnu-emacs

Memnon Anon <gegendosenfleisch@googlemail.com> writes:

> marioepsley <marioepsley@aol.com> writes:
>> I am a complete newbie, i downloaded aquamacs emacs yesterday

Ah, you are probably not that familiar with the emacs info system, yet. 
(You really should learn how to use it properly if you want to stick to
emacs. It is really worth getting accustomed to it!)

So, in case you did not notice:

[ (info "(emacs)Keyboard Macros") ] 

  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use mouse on this ;).

And yes, you can use awk, pipes, regexes etc. There are lots of ways.

But, as you are no "coder" and an emacs beginner, I'd really say: Go for
the Keyboard Macros [F3+F4 or C-x ( and C-x )]. They will be usefull
again and again.







^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Easy for Some
       [not found] <mailman.707.1262616303.18930.help-gnu-emacs@gnu.org>
  2010-01-05 10:01 ` Anselm Helbig
@ 2010-01-05 21:54 ` Colin S. Miller
  1 sibling, 0 replies; 10+ messages in thread
From: Colin S. Miller @ 2010-01-05 21:54 UTC (permalink / raw
  To: help-gnu-emacs

marioepsley wrote:
> I'm not coder but i needed to extract some information from a text file and
> some one pointed me in this direction. 
> 
> I have a file like this, could have up to a 1000 keyframes.:
> 
> 
> 
> Effects   Sound Keys #1   Output 1 #22
>    Frame
>    0   0.17489
>    1   0.261281
>    2   0.361762
>    3   0.400085
>    4   0.411538
>    5   0.434799
>    6   0.41712
>    7   0.422151
>    8   0.43181
>    9   0.411811
> 
Mario,

Or, skipping emacs all together, use AWK

awk -F \\t '{print $2}' < input.txt | tr -d ' ' > output.txt

This AWK command sets the field delimiter to TAB (aka \\t),
and prints the second field from each line in the file.
The tr command deletes all spaces from its input.

If you use MS-Windows, only use one \

HTH,
Colin S. Miller


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2010-01-05 21:54 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20100104155525.0A1DC83814@mxperim8.sea5.speakeasy.net>
2010-01-04 10:25 ` Easy for Some marioepsley
2010-01-04 16:28   ` Vicente Hernando Ara
2010-01-04 17:45   ` Peter Dyballa
2010-01-05  2:23     ` Kevin Rodgers
2010-01-04 20:40   ` Andreas Politz
2010-01-05  2:44   ` Steve Revilak
2010-01-05 15:40   ` Memnon Anon
2010-01-05 17:33     ` Memnon Anon
     [not found] <mailman.707.1262616303.18930.help-gnu-emacs@gnu.org>
2010-01-05 10:01 ` Anselm Helbig
2010-01-05 21:54 ` Colin S. Miller

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.