PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > Updating numeric values from shell script
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Updating numeric values from shell script

Réponse
 
LinkBack Outils de la discussion
Vieux 22/07/2007, 12h03   #1
bcpkh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Updating numeric values from shell script

Hello all

Have the following problem, can someone please . I need to do this
in a Unix Shell script.

I have a text file with the following two lines in the file;

Audit_Value_1: 10000
Audit_Value_2: 5764.34

The followng should happen:
1. Read values

2. calc new values;
x=10000-1
y=5764.34 - 2.4

3.Replace original lines in file with;
Audit_Value_1: 9999
Audit_Value_2: 5761.94

Your would be appreciated.

Thanks,

B

  Réponse avec citation
Vieux 22/07/2007, 12h54   #2
Janis Papanagnou
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Updating numeric values from shell script

bcpkh wrote:
> Hello all
>
> Have the following problem, can someone please . I need to do this
> in a Unix Shell script.
>
> I have a text file with the following two lines in the file;
>
> Audit_Value_1: 10000
> Audit_Value_2: 5764.34
>
> The followng should happen:
> 1. Read values
>
> 2. calc new values;
> x=10000-1
> y=5764.34 - 2.4
>
> 3.Replace original lines in file with;
> Audit_Value_1: 9999
> Audit_Value_2: 5761.94


I think you mean "Replace original lines in file with calculated values"
(otherwise you don't need step 2 if you just want to replace them by a
constant string).

>
> Your would be appreciated.


awk '
$1 == "Audit_Value_1:" { $2 -= 1 }
$1 == "Audit_Value_2:" { $2 -= 2.4 }
{ print }
' your_text_file


Janis

>
> Thanks,
>
> B
>

  Réponse avec citation
Vieux 22/07/2007, 12h54   #3
Janis Papanagnou
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Updating numeric values from shell script

bcpkh wrote:
> Hello all
>
> Have the following problem, can someone please . I need to do this
> in a Unix Shell script.
>
> I have a text file with the following two lines in the file;
>
> Audit_Value_1: 10000
> Audit_Value_2: 5764.34
>
> The followng should happen:
> 1. Read values
>
> 2. calc new values;
> x=10000-1
> y=5764.34 - 2.4
>
> 3.Replace original lines in file with;
> Audit_Value_1: 9999
> Audit_Value_2: 5761.94


I think you mean "Replace original lines in file with calculated values"
(otherwise you don't need step 2 if you just want to replace them by a
constant string).

>
> Your would be appreciated.


awk '
$1 == "Audit_Value_1:" { $2 -= 1 }
$1 == "Audit_Value_2:" { $2 -= 2.4 }
{ print }
' your_text_file


Janis

>
> Thanks,
>
> B
>

  Réponse avec citation
Vieux 22/07/2007, 13h12   #4
bcpkh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Updating numeric values from shell script

On Jul 22, 1:54 pm, Janis Papanagnou <Janis_Papanag...@hotmail.com>
wrote:
> bcpkh wrote:
> > Hello all

>
> > Have the following problem, can someone please . I need to do this
> > in a Unix Shell script.

>
> > I have a text file with the following two lines in the file;

>
> > Audit_Value_1: 10000
> > Audit_Value_2: 5764.34

>
> > The followng should happen:
> > 1. Read values

>
> > 2. calc new values;
> > x=10000-1
> > y=5764.34 - 2.4

>
> > 3.Replace original lines in file with;
> > Audit_Value_1: 9999
> > Audit_Value_2: 5761.94

>
> I think you mean "Replace original lines in file with calculated values"
> (otherwise you don't need step 2 if you just want to replace them by a
> constant string).
>
>
>
> > Your would be appreciated.

>
> awk '
> $1 == "Audit_Value_1:" { $2 -= 1 }
> $1 == "Audit_Value_2:" { $2 -= 2.4 }
> { print }
> ' your_text_file
>
> Janis
>
>
>
>
>
> > Thanks,

>
> > B- Hide quoted text -

>
> - Show quoted text -- Hide quoted text -
>
> - Show quoted text -


Hello Janis

'Replace original lines in file with calculated values' is indeed
exactly what I meant and thanks for the advice!

B

  Réponse avec citation
Vieux 22/07/2007, 13h12   #5
bcpkh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Updating numeric values from shell script

On Jul 22, 1:54 pm, Janis Papanagnou <Janis_Papanag...@hotmail.com>
wrote:
> bcpkh wrote:
> > Hello all

>
> > Have the following problem, can someone please . I need to do this
> > in a Unix Shell script.

>
> > I have a text file with the following two lines in the file;

>
> > Audit_Value_1: 10000
> > Audit_Value_2: 5764.34

>
> > The followng should happen:
> > 1. Read values

>
> > 2. calc new values;
> > x=10000-1
> > y=5764.34 - 2.4

>
> > 3.Replace original lines in file with;
> > Audit_Value_1: 9999
> > Audit_Value_2: 5761.94

>
> I think you mean "Replace original lines in file with calculated values"
> (otherwise you don't need step 2 if you just want to replace them by a
> constant string).
>
>
>
> > Your would be appreciated.

>
> awk '
> $1 == "Audit_Value_1:" { $2 -= 1 }
> $1 == "Audit_Value_2:" { $2 -= 2.4 }
> { print }
> ' your_text_file
>
> Janis
>
>
>
>
>
> > Thanks,

>
> > B- Hide quoted text -

>
> - Show quoted text -- Hide quoted text -
>
> - Show quoted text -


Hello Janis

'Replace original lines in file with calculated values' is indeed
exactly what I meant and thanks for the advice!

B

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 13h29.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11132 seconds with 13 queries