Need help from sed guru

Need help from sed guru

Post by Richar » Wed, 02 Feb 2000 04:00:00



Hello all,

I need to change the format of a line and want to use sed:

input:

item1   |   123.670,00-|   345.760 | text1

I want to change the item 123.670,00- to -123.670,00 so
the output would be:

item1   |  -123.670,00 |   345.760 | text1

I've been on this the whole day and can't get it right
please help !

greetings,
Richard.

 
 
 

Need help from sed guru

Post by Snogfest Hosebeas » Wed, 02 Feb 2000 04:00:00




Quote:> Hello all,

> I need to change the format of a line and want to use sed:

> input:

> item1   |   123.670,00-|   345.760 | text1

> I want to change the item 123.670,00- to -123.670,00 so
> the output would be:

> item1   |  -123.670,00 |   345.760 | text1

> I've been on this the whole day and can't get it right
> please help !

> greetings,
> Richard.

hmm, I may have the wrong end of the stick here, but

put these into a file
s/-$//
s/^/-/

then
sed -f sed.file input.file

HTH (but bet it doesn't)
--
I like traffic lights
I like traffic lights
I like traffic lights
but only when they're green

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

Need help from sed guru

Post by boba.. » Wed, 02 Feb 2000 04:00:00







> > Hello all,

> > I need to change the format of a line and
want to use sed:

> > input:

> > item1   |   123.670,00-|   345.760 | text1

> > I want to change the item 123.670,00- to -
123.670,00 so
> > the output would be:

> > item1   |  -123.670,00 |   345.760 | text1

> > I've been on this the whole day and can't get
it right
> > please help !

> > greetings,
> > Richard.

> hmm, I may have the wrong end of the stick
here, but

> put these into a file
> s/-$//
> s/^/-/

> then
> sed -f sed.file input.file

> HTH (but bet it doesn't)
> --
> I like traffic lights
> I like traffic lights
> I like traffic lights
> but only when they're green

> Sent via Deja.com http://www.deja.com/
> Before you buy.

$ cat xx
item1  |  123.670,00-|  345.760 | text1

$ sed 's/\([0-9.,]*\)-/-\1/' xx
item1  |  -123.670,00|  345.760 | text1

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

Need help from sed guru

Post by Matthew Land » Wed, 02 Feb 2000 04:00:00



> Hello all,

> I need to change the format of a line and want to use sed:

> input:

> item1   |   123.670,00-|   345.760 | text1

> I want to change the item 123.670,00- to -123.670,00 so
> the output would be:

> item1   |  -123.670,00 |   345.760 | text1

> I've been on this the whole day and can't get it right
> please help !

> greetings,
> Richard.

sed 's/\([0-9,.]*\)-/-\1 /'

This will take the FIRST occurance of a string with any number
of DIGITS, COMMAS, and PERIODS, followed by a MINUS sign, and
put the MINUS sign at the beginning.

If the second number is ALWAYS XXX.XXX,XX- where X is a digit,
you can be more secure in pattern checking (and limited too)
with

sed 's/\([0-9]\{3\}.[0-9]\{3\},[0-9]\{2\}\)-/-\1 /'

 - Matt

--

  AIX and HACMP Certified Specialist    | |  / \ |\| |  \. ,_|    _| --
  / Comments, views, and opinions \     | |_/ ^ \|   | ) | |      \, *_)
  \ are mine alone, not IBM's.    /     |___|/~\_\_|\|__/|_|        \(

 
 
 

Need help from sed guru

Post by Bruce Elric » Wed, 02 Feb 2000 04:00:00








> > > Hello all,

> > > I need to change the format of a line and
> want to use sed:

> > > input:

> > > item1   |   123.670,00-|   345.760 | text1

> > > I want to change the item 123.670,00- to -
> 123.670,00 so
> > > the output would be:

> > > item1   |  -123.670,00 |   345.760 | text1
...
> $ cat xx
> item1  |  123.670,00-|  345.760 | text1

> $ sed 's/\([0-9.,]*\)-/-\1/' xx
> item1  |  -123.670,00|  345.760 | text1

You may want to tag a 'g' on the end of that, in case the input has two fields
with the trailing negative that you want to change to a leading negative:
$ cat xx
item1  |  123.670,00-|  345.760 | text1
item1  |  123.670,00-|  345.760-| text1
$ sed 's/\([0-9.,]*\)-/-\1/g' xx
item1  |  -123.670,00|  345.760 | text1
item1  |  -123.670,00|  -345.760| text1

Or if all the number fields have leading spaces:
$ sed 's/ \([0-9.,]*\)-/-\1 /g' xx
item1  | -123.670,00 |  345.760 | text1
item1  | -123.670,00 | -345.760 | text1

Cheers...
Bruce
--
Bruce Elrick, Ph.D.                       Saltus Technology Consulting Group


 
 
 

Need help from sed guru

Post by Richar » Thu, 03 Feb 2000 04:00:00


Thanks to all of you,

The final version I use now is : sed 's/ \([0-9.]*\,[0-9]\{2\}\)-/-\1 /g

This keep the format ok and only changes the - signs for numbers that
have ,XX- on the end

greetings,

Richard.