Question Ecrire en bout de ligne dans un csv

Plus d'informations
il y a 12 ans 5 mois #16082 par Carrieu
Bonjour,

Je souhaite écrire à la fin d'une ligne dans un fichier csv.

Mon fichier actuel est comme ceci :

Serveur, nomfichier, status, modification, datemodif
SRV01, toto.txt, txt
SRV02, toto.txt, txt
etc...


Voila ce que je j'aimerais avoir :

Serveur, nomfichier, status, modification, datemodif
SRV01, toto.txt, txt, (Oui ou non), 03/10/2013
SRV02, toto.txt, txt, (Oui ou non), 03/10/2013
etc...

Si quelqu'un peut m'aider :)
Merci d'avance pour votre aide.

Je reste a dispo si je n'ai pas été claire.

Max.

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 12 ans 5 mois #16083 par Laurent Dardenne
Une possible solution rapido :
[code:1]
$file='c:\temp\test.csv'
@'
Serveur, nomfichier, status, modification, datemodif
SRV01, toto.txt, txt
SRV02, toto.txt, txt
'@ > $File

$next=$true
$Result=Foreach ($line in Get-Content $File){
if ($next)
{
$next=$false
Write-output $line
continue
}
Write-output \"${line}, (Oui ou non), 03/10/2013\"
}
$Result|set-content 'c:\temp\test2.csv'
$objets=import-csv 'c:\temp\test2.csv'
[/code:1]

Tutoriels PowerShell

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 12 ans 5 mois #16091 par Carrieu
Sa marche parfaitement comme je le désire !!
Un grand merci a toi :)
A bientôt.

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 12 ans 5 mois #16093 par Matthew BETTON
Bonjour,

Une autre solution :

[code:1]
$file='c:\temp\test.csv'
@'
Serveur, nomfichier, status, modification, datemodif
SRV01, toto.txt, txt
SRV02, toto.txt, txt
'@ > $File

$Result = Import-Csv $File | ForEach-Object { $_.modification = \"(Oui ou non)\" ; $_.datemodif = \"03/10/2013\"
; $_ }
$Result | Export-Csv C:\Temp\test2.csv -NoTypeInformation
[/code:1]

@ +

Matthew<br><br>Message édité par: Matthew BETTON, à: 4/10/13 14:01

Connexion ou Créer un compte pour participer à la conversation.

Temps de génération de la page : 0.044 secondes
Propulsé par Kunena