Comparing values of two consequent lines

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Comparing values of two consequent lines

tuxic
Hi,

I have a textfile with lot of lines.
These lines have the following format

<command> a-<name of parameter> <value>
<command> b-<name of parameter> <value>

where
<command> is a command identical for all lines
<name of parameter> are different commands.
<value> is a numeric value.

The commands are paired. A certain command exist in
the form 'a-command' and 'b-command'.

The lines are sorted in way that lines with a certain
command ("a-" and "b-" form) are always paired and
grouped together.

I want to check, whether all paired lines have attached
the same value.

There are way too many lines to do this manually and doing
so would be much too error prone.

Can this done with vim automagically and how?
Or: Is there already a unix tool (I am on Linux), which
could do this check?

Thanks a lot for any help in advance!
Cheers!
Meino



--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Comparing values of two consequent lines

Efraim Yawitz
Sounds like a job for awk, but I'm sure someone here will have a more detailed idea.

On Thu, Mar 29, 2018 at 9:51 AM, <[hidden email]> wrote:
Hi,

I have a textfile with lot of lines.
These lines have the following format

<command> a-<name of parameter> <value>
<command> b-<name of parameter> <value>

where
<command> is a command identical for all lines
<name of parameter> are different commands.
<value> is a numeric value.

The commands are paired. A certain command exist in
the form 'a-command' and 'b-command'.

The lines are sorted in way that lines with a certain
command ("a-" and "b-" form) are always paired and
grouped together.

I want to check, whether all paired lines have attached
the same value.

There are way too many lines to do this manually and doing
so would be much too error prone.

Can this done with vim automagically and how?
Or: Is there already a unix tool (I am on Linux), which
could do this check?

Thanks a lot for any help in advance!
Cheers!
Meino



--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Comparing values of two consequent lines

Tim Chase
In reply to this post by tuxic
On 2018-03-29 08:51, [hidden email] wrote:
> I have a textfile with lot of lines.
> These lines have the following format
>
> <command> a-<name of parameter> <value>
> <command> b-<name of parameter> <value>
[snip]
> I want to check, whether all paired lines have attached
> the same value.

You can find them with

/^command a-\(\w\+\) \+\(\d\+\) *\ncommand b-\1 \+\2\@!

or you can mark them with

:%s/^command a-\(\w\+\) \+\(\d\+\) *\ncommand b-\1 \+\2\@!/& THIS ONE

or indent them with

:g/^command a-\(\w\+\) \+\(\d\+\) *\ncommand b-\1 \+\2\@!/sil .,+>


These assume that "<name of parameter>" can be found by the regex
"\w\+", so modify accordingly if needed.

-tim



--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Comparing values of two consequent lines

Tim Chase
On 2018-03-29 06:21, Tim Chase wrote:
> > I want to check, whether all paired lines have attached
> > the same value.  
>
> You can find them with
>
> /^command a-\(\w\+\) \+\(\d\+\) *\ncommand b-\1 \+\2\@!

I suppose I should have offered both alternatives...finding those
that *don't* match, use my previous email. If you want those that
*do* match, use the regex

^command a-\(\w\+\) \+\(\d\+\) *\ncommand b-\1 \+\2$

(change the "\@!" at the end which asserts that the number DOESN'T
match to a "$")

-tim


--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Comparing values of two consequent lines

tuxic
On 03/29 06:55, Tim Chase wrote:

> On 2018-03-29 06:21, Tim Chase wrote:
> > > I want to check, whether all paired lines have attached
> > > the same value.  
> >
> > You can find them with
> >
> > /^command a-\(\w\+\) \+\(\d\+\) *\ncommand b-\1 \+\2\@!
>
> I suppose I should have offered both alternatives...finding those
> that *don't* match, use my previous email. If you want those that
> *do* match, use the regex
>
> ^command a-\(\w\+\) \+\(\d\+\) *\ncommand b-\1 \+\2$
>
> (change the "\@!" at the end which asserts that the number DOESN'T
> match to a "$")
>
> -tim
>
>
> --
> --
> You received this message from the "vim_use" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>
> ---
> You received this message because you are subscribed to the Google Groups "vim_use" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
> For more options, visit https://groups.google.com/d/optout.
>

Hi Tim,

simply amazing! Thanks a lot for your help! THIS will easy my work a
lot!

Cheers!
Meino


--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Comparing values of two consequent lines

Tim Chase
On 2018-03-29 20:34, [hidden email] wrote:

> On 03/29 06:55, Tim Chase wrote:
> > On 2018-03-29 06:21, Tim Chase wrote:  
> > > > I want to check, whether all paired lines have attached
> > > > the same value.    
> > >
> > > /^command a-\(\w\+\) \+\(\d\+\) *\ncommand b-\1 \+\2\@!  
> >
> > ^command a-\(\w\+\) \+\(\d\+\) *\ncommand b-\1 \+\2$
>
> Hi Tim,
>
> simply amazing! Thanks a lot for your help! THIS will easy my work a
> lot!

Another edge-case occurred to me where they differ after a common
subset.  E.g.

 command a-parameter 1
 command b-parameter 11

which might consider them a match/mismatch in one or the other of
those cases so it might require anchoring with either a "\>" or "$" to
ensure the match ends where expected.

-tim




--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.