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

  FORUM HardWare.fr
  Programmation
  Shell/Batch

  batch récupére variable dans un texte

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

batch récupére variable dans un texte

n°1874148
chacal64
Posté le 17-04-2009 à 04:33:00  profilanswer
 

Bonjour, jaimerais faire un batch qui récupèrer dans une variable l'ip suivante "24.212.82.222" comment faire?
tout ce texte est sur une seule ligne dans mon fichier .txt
merci de votre aide.
<P ALIGN="center"><FONT size=8><BR>IP : 24.212.82.222<br></font><font size=3><i>cnq82-222.cablevision.qc.ca</i><br></font><font size=1><br><br>Pas de proxy détecté - No Proxy detected</font></html>

mood
Publicité
Posté le 17-04-2009 à 04:33:00  profilanswer
 

n°1874173
vttman2
Je suis Open ...
Posté le 17-04-2009 à 09:15:02  profilanswer
 

Hello  
 
Sous Windows, Unix ?


---------------
il n'y a pas que le VTT dans la vie, il y a le Snowboard aussi ...
n°1874393
chacal64
Posté le 17-04-2009 à 14:47:52  profilanswer
 

Window XP

n°1874519
eZula
Posté le 17-04-2009 à 18:13:58  profilanswer
 
n°1874564
chacal64
Posté le 17-04-2009 à 20:39:44  profilanswer
 

ca marche pas  
grep -o  option invalid
au pire comment récupérer toute la ligne dans une variable?

n°1874565
eZula
Posté le 17-04-2009 à 20:49:14  profilanswer
 

Code :
  1. Bureau>grep --help | grep "  -o"
  2.   -o, --only-matching       show only the part of a line matching PATTERN


 
Comment ça "option invalid" ?
 

Code :
  1. \Bureau>for /F %a in ('grep -o "[0-9]\{2\}\.[0-9]\{3\}\.[0-9]\{2\}\.[0-9]\{3\}" fichier.txt') do set var=%a
  2. \Bureau>set var=24.212.82.222


 
tu utilises quelle version de grep ?

n°1874582
chacal64
Posté le 17-04-2009 à 23:19:32  profilanswer
 

comment voir la version?
 
C:\>grep --help
Usage: grep [OPTION]... PATTERN [FILE] ...
Search for PATTERN in each FILE or standard input.
Example: grep -i 'hello world' menu.h main.c
 
Regexp selection and interpretation:
  -E, --extended-regexp     PATTERN is an extended regular expression
  -F, --fixed-strings       PATTERN is a set of newline-separated strings
  -G, --basic-regexp        PATTERN is a basic regular expression
  -e, --regexp=PATTERN      use PATTERN as a regular expression
  -f, --file=FILE           obtain PATTERN from FILE
  -i, --ignore-case         ignore case distinctions
  -w, --word-regexp         force PATTERN to match only whole words
  -x, --line-regexp         force PATTERN to match only whole lines
  -z, --null-data           a data line ends in 0 byte, not newline
 
Miscellaneous:
  -s, --no-messages         suppress error messages
  -v, --invert-match        select non-matching lines
  -V, --version             print version information and exit
      --help                display this help and exit
      --mmap                use memory-mapped input if possible
 
Output control:
  -b, --byte-offset         print the byte offset with output lines
  -n, --line-number         print line number with output lines
  -H, --with-filename       print the filename for each match
  -h, --no-filename         suppress the prefixing filename on output
  -q, --quiet, --silent     suppress all normal output
      --binary-files=TYPE   assume that binary files are TYPE
                            TYPE is 'binary', 'text', or 'without-match'.
  -a, --text                equivalent to --binary-files=text
  -I                        equivalent to --binary-files=without-match
  -d, --directories=ACTION  how to handle directories
                            ACTION is 'read', 'recurse', or 'skip'.
  -r, --recursive           equivalent to --directories=recurse.
  -L, --files-without-match only print FILE names containing no match
  -l, --files-with-matches  only print FILE names containing matches
  -c, --count               only print a count of matching lines per FILE
  -Z, --null                print 0 byte after FILE name
 
Context control:
  -B, --before-context=NUM  print NUM lines of leading context
  -A, --after-context=NUM   print NUM lines of trailing context
  -C, --context[=NUM]       print NUM (default 2) lines of output context
                            unless overridden by -A or -B
  -NUM                      same as --context=NUM
  -U, --binary              do not strip CR characters at EOL (MSDOS)
  -u, --unix-byte-offsets   report offsets as if CRs were not there (MSDOS)
 
`egrep' means `grep -E'.  `fgrep' means `grep -F'.
With no FILE, or when FILE is -, read standard input.  If less than
two FILEs given, assume -h.  Exit status is 0 if match, 1 if no match,
and 2 if trouble.
 
Report bugs to <bug-gnu-utils@gnu.org>.
 
C:\>

n°1874584
eZula
Posté le 17-04-2009 à 23:43:00  profilanswer
 

pour connaitre la version c'est écrit dans le manuel  ;)  
 

Code :
  1. -V, --version             print version information and exit


 
moi j'utilise celle-ci sous windows http://downloads.sourceforge.net/g [...] .4-bin.zip (avec bien sur les dépendances http://downloads.sourceforge.net/g [...] .4-dep.zip )
 
l'option -o est bien pratique pour encadrer strictement le motif recherché

n°1874586
chacal64
Posté le 18-04-2009 à 00:25:16  profilanswer
 


C:\>grep -V
grep (GNU grep) 2.4.2
 
Copyright 1988, 1992-1999, 2000 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
 
C:\>

n°1874587
chacal64
Posté le 18-04-2009 à 00:35:13  profilanswer
 

J ai installer nouvelle version
la fenetre se ferme
meme avec un pause

mood
Publicité
Posté le 18-04-2009 à 00:35:13  profilanswer
 

n°1874588
eZula
Posté le 18-04-2009 à 00:36:06  profilanswer
 

Utilise la version que je t'ai indiqué, elle est plus récente (GNU grep 2.5.4)
 
edit > tu as les dépendances avec ?


Message édité par eZula le 18-04-2009 à 00:37:20
n°1874592
chacal64
Posté le 18-04-2009 à 01:43:34  profilanswer
 

oui j ai installé les deux  
grep -V  = 2.5.4

n°1874594
chacal64
Posté le 18-04-2009 à 01:47:22  profilanswer
 

j ai ajouté un % la fenetre ne ferme pu mais me donne ceci
 
 
C:\>for /F %a in ('grep -o "[0-9]\{2\}\.[0-9]\{3\}\.[0-9]\{2\}\.[0-9]\{3\}"c:\ipconfig.txt') do set
var=%a
grep: (standard input): Not enough space
 
C:\>pause
Appuyez sur une touche pour continuer...

n°1874610
eZula
Posté le 18-04-2009 à 09:54:36  profilanswer
 

Il te manque un espace entre {3\}" et c:\ipconfig.txt

n°1874728
chacal64
Posté le 18-04-2009 à 19:00:41  profilanswer
 

En effet ca marche a merveille.
merci beaucoup.
t'est un vrai "pro"
Résolu


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

  batch récupére variable dans un texte

 

Sujets relatifs
utiliser le & dans un jcl comme etant un caractere et non variableVBS ouvert par un fichier batch
[Résolu] Comment récupérer une variable asp en jscript[batch] récupérer le resultat d'une commande dans une variable
Intégré le résultat d'une requête access dans un mail en corp de texte[Batch]Renommer des fichiers[Résolu]
ne conserver que la dernière ligne d' un fichier textevariable dernier caractere texte
Plus de sujets relatifs à : batch récupére variable dans un texte


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