2009-06-30 5 views
0

Comment puis-je trouver et afficher le mot iperf de $ dans un fichier

Le fichier ressemblera à ceci

$iperf -c 172.29.38.67 -m -M 64 -i 5 -t 20 -P 10 
WARNING: attempt to set TCP maximum segment size to 64, but got 536 
WARNING: attempt to set TCP maximum segment size to 64, but got 536 
WARNING: attempt to set TCP maximum segment size to 64, but got 536 
WARNING: attempt to set TCP maximum segment size to 64, but got 536 
WARNING: attempt to set TCP maximum segment size to 64, but got 536 
WARNING: attempt to set TCP maximum segment size to 64, but got 536 
WARNING: attempt to set TCP maximum segment size to 64, but got 536 
WARNING: attempt to set TCP maximum segment size to 64, but got 536 
WARNING: attempt to set TCP maximum segment size to 64, but got 536 
WARNING: attempt to set TCP maximum segment size to 64, but got 536 
------------------------------------------------------------ 

~ $ iperf -c 172.29.38.67 -m -M 128 -i 5 -t 20 -P 10 
WARNING: attempt to set TCP maximum segment size to 128, but got 536 
WARNING: attempt to set TCP maximum segment size to 128, but got 536 
WARNING: attempt to set TCP maximum segment size to 128, but got 536 
WARNING: attempt to set TCP maximum segment size to 128, but got 536 
WARNING: attempt to set TCP maximum segment size to 128, but got 536 
WARNING: attempt to set TCP maximum segment size to 128, but got 536 
WARNING: attempt to set TCP maximum segment size to 128, but got 536 
WARNING: attempt to set TCP maximum segment size to 128, but got 536 
WARNING: attempt to set TCP maximum segment size to 128, but got 536 
WARNING: attempt to set TCP maximum segment size to 128, but got 536 
------------------------------------------------------------ 
Client connecting to 172.29.38.67, TCP port 5001 
TCP window size: 16.0 KByte (default) 
------------------------------------------------------------ 
+1

Voulez-vous littéralement rechercher et trouver "$ iperf" ou est-ce supposé être un espace réservé de quelque sorte? Lorsque vous publiez du code ou un long journal comme celui-ci, il est courtois d'utiliser le bouton de format Code ou Citation approprié pour le rendre joli. – colithium

+0

Vote pour fermer car il n'y a pas de question en vue. –

Répondre

1

On dirait que vous avez besoin une regex. La chaîne '$iperf' n'existe pas dans vos données, donc je vais supposer que vous voulez dire 'iperf'. Vous pouvez trouver les lignes qui contiennent cette chaîne en faisant une boucle sur le fichier une ligne à la fois et en testant chaque ligne avec une regex. Si l'expression régulière réussit, vous pouvez imprimer la ligne.

#!/usr/bin/perl 

use strict; 
use warnings; 

while (<DATA>) { 
    print if /\biperf\b/; 
} 

__DATA__ 
$iperf -c 172.29.38.67 -m -M 64 -i 5 -t 20 -P 10 
WARNING: attempt to set TCP maximum segment size to 64, but got 536 
WARNING: attempt to set TCP maximum segment size to 64, but got 536 
WARNING: attempt to set TCP maximum segment size to 64, but got 536 
WARNING: attempt to set TCP maximum segment size to 64, but got 536 
WARNING: attempt to set TCP maximum segment size to 64, but got 536 
WARNING: attempt to set TCP maximum segment size to 64, but got 536 
WARNING: attempt to set TCP maximum segment size to 64, but got 536 
WARNING: attempt to set TCP maximum segment size to 64, but got 536 
WARNING: attempt to set TCP maximum segment size to 64, but got 536 
WARNING: attempt to set TCP maximum segment size to 64, but got 536 
------------------------------------------------------------ 

~ $ iperf -c 172.29.38.67 -m -M 128 -i 5 -t 20 -P 10 
WARNING: attempt to set TCP maximum segment size to 128, but got 536 
WARNING: attempt to set TCP maximum segment size to 128, but got 536 
WARNING: attempt to set TCP maximum segment size to 128, but got 536 
WARNING: attempt to set TCP maximum segment size to 128, but got 536 
WARNING: attempt to set TCP maximum segment size to 128, but got 536 
WARNING: attempt to set TCP maximum segment size to 128, but got 536 
WARNING: attempt to set TCP maximum segment size to 128, but got 536 
WARNING: attempt to set TCP maximum segment size to 128, but got 536 
WARNING: attempt to set TCP maximum segment size to 128, but got 536 
WARNING: attempt to set TCP maximum segment size to 128, but got 536 
------------------------------------------------------------ 
Client connecting to 172.29.38.67, TCP port 5001 
TCP window size: 16.0 KByte (default) 
------------------------------------------------------------ 
Questions connexes