Skip to main content
added 3 characters in body
Source Link
mikeserv
  • 59.4k
  • 10
  • 123
  • 243

You need to forget the negative entirely - leave it out. You want to consolidate two fields - from left to right. That's very easy.

sed ' s/ *\(.*\)/\1 / s/\([0-9]* *\)\{2\}/\1/g s/[ *$-]*$// ' <<\IN -1 2 3 4 -5 9 2 3 -4 5 -6 11 IN -2 4 -9 3 -5 -11 

Notice how I avoid any reference to the sign at all - when the input is processed the automaton will accept only spaces or numbers because it understands nothing else - all else is ignored completely and will remain in place.

When you specify a \{numeric repetition interval\} for a \(subexpression\), only the last occurrence of that expression is \1 back-referenced. So you can just squeeze - or truncate - a repeat interval that easily. And because we squeeze the repeat behind the sign - if there is one - the second occurrence of that pattern will follow any sign that used to precede the first.

The behavior described above is specified by POSIX for all BRE compliant applications, but very few seds get it right. GNU sed does.

Last, the spaces are just to make the pattern occurrence regular.

Of course, this will never work for you. Or, probably more correctly, it will always work for you, but never return any results. How could it if the pattern is indefinite?

You need to forget the negative entirely - leave it out. You want to consolidate two fields - from left to right. That's very easy.

sed ' s/ *\(.*\)/\1 / s/\([0-9]* *\)\{2\}/\1/g s/ *$// ' <<\IN -1 2 3 4 -5 9 2 3 -4 5 -6 11 IN -2 4 -9 3 -5 -11 

Notice how I avoid any reference to the sign at all - when the input is processed the automaton will accept only spaces or numbers because it understands nothing else - all else is ignored completely and will remain in place.

When you specify a \{numeric repetition interval\} for a \(subexpression\), only the last occurrence of that expression is \1 back-referenced. So you can just squeeze - or truncate - a repeat interval that easily. And because we squeeze the repeat behind the sign - if there is one - the second occurrence of that pattern will follow any sign that used to precede the first.

The behavior described above is specified by POSIX for all BRE compliant applications, but very few seds get it right. GNU sed does.

Last, the spaces are just to make the pattern occurrence regular.

Of course, this will never work for you. Or, probably more correctly, it will always work for you, but never return any results. How could it if the pattern is indefinite?

You need to forget the negative entirely - leave it out. You want to consolidate two fields - from left to right. That's very easy.

sed ' s/ *\(.*\)/\1 / s/\([0-9]* *\)\{2\}/\1/g s/[ -]*$// ' <<\IN -1 2 3 4 -5 9 2 3 -4 5 -6 11 IN -2 4 -9 3 -5 -11 

Notice how I avoid any reference to the sign at all - when the input is processed the automaton will accept only spaces or numbers because it understands nothing else - all else is ignored completely and will remain in place.

When you specify a \{numeric repetition interval\} for a \(subexpression\), only the last occurrence of that expression is \1 back-referenced. So you can just squeeze - or truncate - a repeat interval that easily. And because we squeeze the repeat behind the sign - if there is one - the second occurrence of that pattern will follow any sign that used to precede the first.

The behavior described above is specified by POSIX for all BRE compliant applications, but very few seds get it right. GNU sed does.

Last, the spaces are just to make the pattern occurrence regular.

Of course, this will never work for you. Or, probably more correctly, it will always work for you, but never return any results. How could it if the pattern is indefinite?

added 2 characters in body
Source Link
mikeserv
  • 59.4k
  • 10
  • 123
  • 243

You need to forget the negative entirely - leave it out. You want to consolidate two rowsfields - from left to right. That's very easy.

sed ' s/ *\(.*\)/\1 / s/\([0-9]* *\)\{2\}/\1/g s/ *$// ' <<\IN -1 2 3 4 -5 9 2 3 -4 5 -6 11 IN -2 4 -9 3 -5 -11 

Notice how I avoid any reference to the sign at all - when the input is processed the automaton will accept only spaces or numbers because it understands nothing else - all else is ignored completely and will remain in place.

When you specify a \{numeric repetition interval\} for a \(subexpression\), only the last occurrence of that expression is \1 back-referenced. So you can just squeeze - or truncate - a repeat interval that easily. And because we squeeze the repeat behind the sign - if there is one - the second occurrence of that pattern will follow any sign that used to precede the first.

The behavior described above is specified by POSIX for all BRE compliant applications, but very few seds get it right. GNU sed does.

Last, the spaces are just to make the pattern occurrence regular.

Of course, this will never work for you. Or, probably more correctly, it will always work for you, but never return any results. How could it if the pattern is indefinite?

You need to forget the negative entirely - leave it out. You want to consolidate two rows - from left to right. That's very easy.

sed ' s/ *\(.*\)/\1 / s/\([0-9]* *\)\{2\}/\1/g s/ *$// ' <<\IN -1 2 3 4 -5 9 2 3 -4 5 -6 11 IN -2 4 -9 3 -5 -11 

Notice how I avoid any reference to the sign at all - when the input is processed the automaton will accept only spaces or numbers because it understands nothing else - all else is ignored completely and will remain in place.

When you specify a \{numeric repetition interval\} for a \(subexpression\), only the last occurrence of that expression is \1 back-referenced. So you can just squeeze - or truncate - a repeat interval that easily. And because we squeeze the repeat behind the sign - if there is one - the second occurrence of that pattern will follow any sign that used to precede the first.

The behavior described above is specified by POSIX for all BRE compliant applications, but very few seds get it right. GNU sed does.

Last, the spaces are just to make the pattern occurrence regular.

Of course, this will never work for you. Or, probably more correctly, it will always work for you, but never return any results. How could it if the pattern is indefinite?

You need to forget the negative entirely - leave it out. You want to consolidate two fields - from left to right. That's very easy.

sed ' s/ *\(.*\)/\1 / s/\([0-9]* *\)\{2\}/\1/g s/ *$// ' <<\IN -1 2 3 4 -5 9 2 3 -4 5 -6 11 IN -2 4 -9 3 -5 -11 

Notice how I avoid any reference to the sign at all - when the input is processed the automaton will accept only spaces or numbers because it understands nothing else - all else is ignored completely and will remain in place.

When you specify a \{numeric repetition interval\} for a \(subexpression\), only the last occurrence of that expression is \1 back-referenced. So you can just squeeze - or truncate - a repeat interval that easily. And because we squeeze the repeat behind the sign - if there is one - the second occurrence of that pattern will follow any sign that used to precede the first.

The behavior described above is specified by POSIX for all BRE compliant applications, but very few seds get it right. GNU sed does.

Last, the spaces are just to make the pattern occurrence regular.

Of course, this will never work for you. Or, probably more correctly, it will always work for you, but never return any results. How could it if the pattern is indefinite?

added 12 characters in body
Source Link
mikeserv
  • 59.4k
  • 10
  • 123
  • 243

You need to forget the negative entirely - leave it out. You want to consolidate two rows - from left to right. That's very easy.

sed 's' s/ *\(.*\)/\1 /;s s/\([0-9]* *\)\{2\}/\1/g;sg s/ *$//  ' <<\IN -1 2 3 4 -5 9 2 3 -4 5 -6 11 IN -2 4 -9 3 -5 -11 

Notice how I avoid any reference to the sign at all - when the input is processed the automaton will accept only spaces or numbers because it understands nothing else - all else is ignored completely and will remain in place.

When you specify a \{numeric repetition interval\} for a \(subexpression\), only the last occurrence of that expression is \1 back-referenced. So you can just squeeze - or truncate - a repeat interval that easily. And because we squeeze the repeat behind the sign - if there is one - the second occurrence of that pattern will follow any sign that used to precede the first.

The behavior described above is specified by POSIX for all BRE compliant applications, but very few seds get it right. GNU sed does.

Last, the spaces are just to make the pattern occurrence regular.

Of course, this will never work for you. Or, probably more correctly, it will always work for you, but never return any results. How could it if the pattern is indefinite?

You need to forget the negative entirely - leave it out. You want to consolidate two rows - from left to right. That's very easy.

sed 's/ *\(.*\)/\1 /;s/\([0-9]* *\)\{2\}/\1/g;s/ *$//' <<\IN -1 2 3 4 -5 9 2 3 -4 5 -6 11 IN -2 4 -9 3 -5 -11 

Notice how I avoid any reference to the sign at all - when the input is processed the automaton will accept only spaces or numbers because it understands nothing else - all else is ignored completely and will remain in place.

When you specify a \{numeric repetition interval\} for a \(subexpression\), only the last occurrence of that expression is \1 back-referenced. So you can just squeeze - or truncate - a repeat interval that easily. And because we squeeze the repeat behind the sign - if there is one - the second occurrence of that pattern will follow any sign that used to precede the first.

The behavior described above is specified by POSIX for all BRE compliant applications, but very few seds get it right. GNU sed does.

Last, the spaces are just to make the pattern occurrence regular.

Of course, this will never work for you. Or, probably more correctly, it will always work for you, but never return any results. How could it if the pattern is indefinite?

You need to forget the negative entirely - leave it out. You want to consolidate two rows - from left to right. That's very easy.

sed ' s/ *\(.*\)/\1 / s/\([0-9]* *\)\{2\}/\1/g s/ *$//  ' <<\IN -1 2 3 4 -5 9 2 3 -4 5 -6 11 IN -2 4 -9 3 -5 -11 

Notice how I avoid any reference to the sign at all - when the input is processed the automaton will accept only spaces or numbers because it understands nothing else - all else is ignored completely and will remain in place.

When you specify a \{numeric repetition interval\} for a \(subexpression\), only the last occurrence of that expression is \1 back-referenced. So you can just squeeze - or truncate - a repeat interval that easily. And because we squeeze the repeat behind the sign - if there is one - the second occurrence of that pattern will follow any sign that used to precede the first.

The behavior described above is specified by POSIX for all BRE compliant applications, but very few seds get it right. GNU sed does.

Last, the spaces are just to make the pattern occurrence regular.

Of course, this will never work for you. Or, probably more correctly, it will always work for you, but never return any results. How could it if the pattern is indefinite?

Source Link
mikeserv
  • 59.4k
  • 10
  • 123
  • 243
Loading