Tirer un fichier .txt
Bonjour à tous,
Je suis en grosse difficulté ... Je dois trier un fichier .txt qui contient beaucoup de ligne en fonction d'un segment qui s'incrémente.
Les données se présente de la manière suivante :
8065,5469 600 35,967056 -771494
8065,6475 600 33,446327 -702830,94
8065,748 600 31,301811 -692456,63
8065,8486 600 29,542171 -677388,31
8065,9492 600 28,297636 -652515,63
8066,7539 601 36,346115 762461,75
8087,9189 604 33,263905 760597,81
8069,0674 602 32,022938 745007,44
Et le but, serait de pouvoir trier les différentes lignes en fonction des valeurs en rouge (au-dessus), dans un ordre croissant. Le problème c'est que je ne sais pas comment faire pour résoudre ce problème.
Si quelqu'un peut m'aider ou m'apporter des éléments de réponses ce serait vraiment cool =D.
Merci d'avance.
Bonjour,
Merci de joindre le fichier texte, en totalité ou en partie.
Préciser le résultat attendu.
@+
Autant pour moi.
Voici les deux fichiers joints (avant et après traitement).
Bonjour,
A première vue les données du fichier .txt sont séparées par des tabulations.
Un simple copier/coller des données dans un fichier excel, suivi d'un tri personnalisé fera l'affaire.
Si tu as besoin d'un code VBA (je pense ici inutile), c'est facilement faisable.
Bonjour,
merci pour ta réponse. Toutefois, j'ai besoin de le faire dans le fichier .txt et non pas sur excel (j'ai plus de 2millions de lignes). Le traitement en .txt me fait gagner beaucoup de temps.
D'accord... je ne sais pas si c'est faisable directement dans un fichier .txt .
Je vais laisser quelqu'un de plus calé que moi répondre.
bonjour
salut stif
en route pour des millions de données
il te faut installer Power BI Desktop gratuit puis faire :
- obtenir des données source csv ou texte
- navigue vers ton fichier, "modifier"
- clique sur la flèche dans l'intitulé Column 2, trier par ordre croissant
- "charger"
- créer une table (ne pas sommer les valeurs)
- ensuite voir ici https://docs.microsoft.com/fr-fr/power-bi/power-bi-visualization-export-data
le tout m'a pris 3 minutes
ceci crée un csv (séparateur ; )
par la suite, les étapes entre ********** sont en mémoire et ne nécessitent qu'un clic sur "actualiser.
pas de VBA ni autre macro, ni formule
bon travail
Merci jmd et merci pour ta réponse.
Je ne connaissais et effectivement c'est plutôt sympa.
Par contre, c'est pour le boulot et je ne peux pas installer de logiciel comme Power BI Desktop sur le PC.
Je sais que cela existe et j'ai trouvé des brides d'informations mais Je ne sais pas trop comment m'y prendre
Par exemple j'ai trouvé cette info :
Shell "Sort x:\sort\"fichier".txt /O x:\sort\"fichier_out".txt", vbHide
Bonjour,
@ jmd,
Ton lien explique qu'un export en csv ne peut dépasser 30.000 lignes (et la demande parle de 2 Millions de lignes à traiter).
Est-ce toujours d'actualité avec la version actuelle de Power BI Desktop ?
Cdlt.
Considérations et limitations
Le nombre maximal de lignes pouvant être exportées de Power BI Desktop et du service Power BI au format .csv est de 30 000.
Le nombre maximal de lignes pouvant être exportées au format .xlsx est de 150 000.
aïe !
tu as raison, j'ai vérifié d'autres sources, Microsoft a bridé l'exportation
mais tout espoir n''est pas perdu
U_goffu ,
à quoi va servir le fichier txt trié ?
Le fichier va servir à calculer un couple de glissement moyen en fonction d'un nombre de cycle et par la suite tracer des graphiques.
Bonjour tout le monde,
Alors j'ai réussi à progresser avec diverses sources que j'ai pu trouver sur le net et j'arrive à obtenir un tableau avec toutes mes données utiles et j'arrive à les trier. Cependant, tri se fait sur la totalité de la ligne alors que je voudrais que le paramètre soit le premier caractère.
Je m'explique :
(texte initial)
0 -720.3655
0 -650.255
1 -750.2565
3 -650.458
2 -965.2554
(texte après filtre)
0 -650.255
0 -720.3655
1 -750.2565
2 -965.2554
3 -650.458
Résultat souhaité :
0 -720.3655
0 -650.255
1 -750.2565
2 -965.2554
3 -650.458
Voici l'extrait du code :
Dim Tableau() As String, L() As String
Dim i as Long
Sub test()
i = -1
Do While Not EOF(2)
i = i + 1
ReDim Preserve Tableau(i)
Input #2, Tableau(i)
Loop
QuickSort Tableau(), LBound(Tableau), UBound(Tableau)
For i = 0 To UBound(Tableau)
L = Split(Tableau(i), " ")
'traitement de la ligne...
For j = 0 To UBound(L)
Debug.Print L(j) & "|"; 'Affiche résultat dans fenêtre exécution
Next
Debug.Print 'Saut de ligne
Next
Print #2, Tableau(i)
end sub
Public Sub QuickSort(ByRef vData As Variant, ByVal Low As Long, ByVal Hi As Long)
' Syntax: QuickSort TmpAray(), Low, Hi
' Parameters:
' vData - A variant pointing to an array to be sorted.
' Low - LBounds(vData) low number of elements in the array
' Hi - UBounds(vData) high number of elements in the array
'
' NOTE: I start my arrays with one and not zero.
' Make the appropriate changes to suit your code.
' Test to see if an array was passed
If Not IsArray(vData) Then Exit Sub
' Define local variables
Dim lTmpLow As Long
Dim lTmpHi As Long
Dim lTmpMid As Long
Dim vTempVal As Variant
Dim vTmpHold As Variant
' Initialize local variables
lTmpLow = Low
lTmpHi = Hi
' Leave if there is nothing to sort
If Hi <= Low Then Exit Sub
' Find the middle to start comparing values
lTmpMid = (Low + Hi) \ 2
' Move the item in the middle of the array to the temporary holding area as a point of reference
' while sorting. This will change each time we make a recursive call to this routine.
vTempVal = vData(lTmpMid)
' Loop until we eventually meet in the middle
Do While (lTmpLow <= lTmpHi)
' Always process the low end first. Loop as long the array data element is less than the
' data in the temporary holding area and the temporary low value is less than the maximum
' number of array elements.
Do While (vData(lTmpLow) < vTempVal And lTmpLow < Hi)
lTmpLow = lTmpLow + 1
Loop
' Now, we will process the high end. Loop as long the data in the temporary holding area
' is less than the array data element and the temporary high value is greater than the
' minimum number of array elements.
Do While (vTempVal < vData(lTmpHi) And lTmpHi > Low)
lTmpHi = lTmpHi - 1
Loop
' if the temp low end is less than or equal to the temp high end, then swap places
If (lTmpLow <= lTmpHi) Then
vTmpHold = vData(lTmpLow) ' Move the Low value to Temp Hold
vData(lTmpLow) = vData(lTmpHi) ' Move the high value to the low
vData(lTmpHi) = vTmpHold ' move the Temp Hod to the High
lTmpLow = lTmpLow + 1 ' Increment the temp low counter
lTmpHi = lTmpHi - 1 ' Dcrement the temp high counter
End If
Loop
' If the minimum number of elements in the array is less than the temp high end, then make a
' recursive call to this routine. I always sort the low end of the array first.
If (Low < lTmpHi) Then
QuickSort vData, Low, lTmpHi
End If
' If the temp low end is less than the maximum number of elements in the array, then make a
' recursive call to this routine. The high end is always sorted last.
If (lTmpLow < Hi) Then
QuickSort vData, lTmpLow, Hi
End If
End Sub