2011-09-26 1 views
2

i ont filw avec containtent comme suit:comment rechercher un motif dans un fichier et afficher la ligne sur le terminal?

pid 4565 Process: /my/name/is/4678 +34787[d][email protected]##$ 
pid 33453 Process: /my/name/is/4678 +34787[d][email protected]##werwer$ 
pid 3453345 Process: /my/name/is/4678 +3478[7][email protected]##$ 
pid 12335 Process: /my/name/is/4678 +3478se[r][email protected]##$ 

i besoin ligne contaning "34787 [d] sfh888dfsj @ ## werwer $" ce modèle et ont besoin d'obtenir toute cette ligne sur le terminal ou peut nè redirigé vers un autre fichier. Toute suggestion? Merci d'avance.

+1

'man grep'? cela pourrait-il fonctionner pour toi? –

+0

@ALL Merci pour le support, j'ai obtenu la sortie requise avec l'utilisation de l'option -a, Parce que mon fichier était un fichier binaire, donc pour rechercher un motif nous avons besoin d'une option comme suit: grep -a "mon_pattern" file.log – BSalunke

Répondre

1

Utilisez grep avec le mode de cordes fixes (aka fgrep):

grep -F '+34787[d][email protected]##werwer$' /path/to/my/file 

Run man grep pour en savoir plus.

Si vous avez besoin de rediriger vers un certain fichier de sortie au lieu de normes sortie:

grep -F '+34787[d][email protected]##werwer$' /path/to/my/file > /path/to/my/output 

Run man sh ou man bash et lisez sur Redirections.

0

grep/awk/sed ... de nombreux outils peuvent le faire. exemple grep:

kent$ echo "pid 4565 Process: /my/name/is/4678 +34787[d][email protected]##$ 
    pid 33453 Process: /my/name/is/4678 +34787[d][email protected]##werwer$ 
    pid 3453345 Process: /my/name/is/4678 +3478[7][email protected]##$ 
    pid 12335 Process: /my/name/is/4678 +3478se[r][email protected]##$"|grep '\+34787\[d\][email protected]##werwer\$' 

    pid 33453 Process: /my/name/is/4678 +34787[d][email protected]##werwer$ 
Questions connexes