Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
759 connectés 

  FORUM HardWare.fr
  Programmation
  Shell/Batch

  Besoin d'aide pour script Bash

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Besoin d'aide pour script Bash

n°1935650
sorg
trop sur HFR depuis 2001
Posté le 27-10-2009 à 12:04:17  profilanswer
 

Voilà le problème:
 
J'ai un repertoire qui contient un nombre important de fichier texte ayant tous la meme structure.
exemple:
 

Code :
  1. OziExplorer Map Data File Version 2.1
  2. TOP25 ACCOUS 909_369F a 100 %
  3. ACCOUS.PNG
  4. 1   TIFF scale factor
  5. WGS 84,WGS 84,   0.0000,   0.0000,WGS 84
  6. Reserved 1
  7. Reserved 2
  8. Magnetic Variation,,,E
  9. Map Projection,Latitude/Longitude,PolyCal,No,AutoCalOnly,No,BSBUseWPX,Yes
  10. Point00,xy,     0,     0,in, deg,  42, 58.95202848,N,   0, 36.03347826,W, grid,   ,           ,           ,N
  11. Point01,xy,  4000,     0,in, deg,  42, 59.14924658,N,   0, 28.69705534,W, grid,   ,           ,           ,N
  12. Point02,xy,  4000,  4000,in, deg,  42, 53.76305368,N,   0, 28.43453932,W, grid,   ,           ,           ,N
  13. Point03,xy,     0,  4000,in, deg,  42, 53.56615894,N,   0, 35.75958213,W, grid,   ,           ,           ,N
  14. Point05,xy,     ,     ,in, deg,    ,        ,N,    ,        ,E, grid,   ,           ,           ,N
  15. Point06,xy,     ,     ,in, deg,    ,        ,N,    ,        ,E, grid,   ,           ,           ,N
  16. Point07,xy,     ,     ,in, deg,    ,        ,N,    ,        ,E, grid,   ,           ,           ,N
  17. Point08,xy,     ,     ,in, deg,    ,        ,N,    ,        ,E, grid,   ,           ,           ,N
  18. Point09,xy,     ,     ,in, deg,    ,        ,N,    ,        ,E, grid,   ,           ,           ,N
  19. Point10,xy,     ,     ,in, deg,    ,        ,N,    ,        ,E, grid,   ,           ,           ,N
  20. Point11,xy,     ,     ,in, deg,    ,        ,N,    ,        ,E, grid,   ,           ,           ,N
  21. Point12,xy,     ,     ,in, deg,    ,        ,N,    ,        ,E, grid,   ,           ,           ,N
  22. Point13,xy,     ,     ,in, deg,    ,        ,N,    ,        ,E, grid,   ,           ,           ,N
  23. Point14,xy,     ,     ,in, deg,    ,        ,N,    ,        ,E, grid,   ,           ,           ,N
  24. Point15,xy,     ,     ,in, deg,    ,        ,N,    ,        ,E, grid,   ,           ,           ,N
  25. Point16,xy,     ,     ,in, deg,    ,        ,N,    ,        ,E, grid,   ,           ,           ,N
  26. Point17,xy,     ,     ,in, deg,    ,        ,N,    ,        ,E, grid,   ,           ,           ,N
  27. Point18,xy,     ,     ,in, deg,    ,        ,N,    ,        ,E, grid,   ,           ,           ,N
  28. Point19,xy,     ,     ,in, deg,    ,        ,N,    ,        ,E, grid,   ,           ,           ,N
  29. Point20,xy,     ,     ,in, deg,    ,        ,N,    ,        ,E, grid,   ,           ,           ,N
  30. Point21,xy,     ,     ,in, deg,    ,        ,N,    ,        ,E, grid,   ,           ,           ,N
  31. Point22,xy,     ,     ,in, deg,    ,        ,N,    ,        ,E, grid,   ,           ,           ,N
  32. Point23,xy,     ,     ,in, deg,    ,        ,N,    ,        ,E, grid,   ,           ,           ,N
  33. Point24,xy,     ,     ,in, deg,    ,        ,N,    ,        ,E, grid,   ,           ,           ,N
  34. Point25,xy,     ,     ,in, deg,    ,        ,N,    ,        ,E, grid,   ,           ,           ,N
  35. Point26,xy,     ,     ,in, deg,    ,        ,N,    ,        ,E, grid,   ,           ,           ,N
  36. Point27,xy,     ,     ,in, deg,    ,        ,N,    ,        ,E, grid,   ,           ,           ,N
  37. Point28,xy,     ,     ,in, deg,    ,        ,N,    ,        ,E, grid,   ,           ,           ,N
  38. Point29,xy,     ,     ,in, deg,    ,        ,N,    ,        ,E, grid,   ,           ,           ,N
  39. Point30,xy,     ,     ,in, deg,    ,        ,N,    ,        ,E, grid,   ,           ,           ,N
  40. Projection Setup,    45.000000000,     5.000000000,     0.999600000,            0.00,            0.00,    49.000000000,    45.000000000,,,
  41. Map Feature = MF ; Map Comment = MC     These follow if they exist
  42. Track File = TF      These follow if they exist
  43. Moving Map Parameters = MM?    These follow if they exist_nMM0,Yes
  44. MMPNUM,4
  45. MMPXY,1,0,0
  46. MMPXY,2,4000,0
  47. MMPXY,3,4000,4000
  48. MMPXY,4,0,4000
  49. MMPLL,1,  0.60055797, 42.98253381
  50. MMPLL,2,  0.47828426, 42.98582078
  51. MMPLL,3,  0.47390899, 42.89605089
  52. MMPLL,4,  0.59599304, 42.89276932
  53. MM1B,5.004373
  54. MOP,Map Open Position,0,0
  55. IWH,Map Image Width/Height,4000,4000


 
Il faut que je fasse sur tout ces fichiers exactement la meme modif:
JE dois rajouter un signe - avant le troisième paramètres des 4 lignes MMPLL . (lignes 49 à 52)
Dans notre exemple, ca donnera:
 

Code :
  1. MMPLL,1,  -0.60055797, 42.98253381
  2. MMPLL,2,  -0.47828426, 42.98582078
  3. MMPLL,3,  -0.47390899, 42.89605089
  4. MMPLL,4,  -0.59599304, 42.89276932


 
Le reste des fichiers doit rester inchangé.
 
Comment puis-je faire çà sans trop de galère ?
(Je suis sous ubunutu 9.10 - je préferai donc un script sh ou bash, mais si nécéssaire, je peux faire çà depuis un pc windows).
 
 

mood
Publicité
Posté le 27-10-2009 à 12:04:17  profilanswer
 

n°1935653
pataluc
Posté le 27-10-2009 à 12:22:36  profilanswer
 

avec awk (ou encore sed)...
 
qqchose comme

Code :
  1. awk '/MMPLL/{$2="-"$2} {print $0}' __ton_fichier__

n°1935668
sorg
trop sur HFR depuis 2001
Posté le 27-10-2009 à 13:21:03  profilanswer
 

pataluc a écrit :

avec awk (ou encore sed)...
 
qqchose comme

Code :
  1. awk '/MMPLL/{$2="-"$2} {print $0}' __ton_fichier__



 
Impeccable! Merci de ton aide!
 
Le script final:  

Code :
  1. #!/bin/bash
  2. for nomfichier in *.map
  3. do
  4. awk '/MMPLL/{$2="-"$2} {print $0}' $nomfichier > ../$nomfichier
  5. done
  6. exit 0


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Shell/Batch

  Besoin d'aide pour script Bash

 

Sujets relatifs
Petit soucis de script VBSCodeigniter & ajax : The script tried to execute a method or access a
Diminuer taille du texte dans un scriptbesoin d'aide sur une correction
Aide pour un ProgrammeScript Batch téléchargement http
besoin d'aide sur 2 exercices en pascalaide java: programmation d'une boite a rythme
[BASH] Help! Besoin d'aide pour l'écriture d'un script ... 
Plus de sujets relatifs à : Besoin d'aide pour script Bash


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR