Grep from beginning of found word to end of word

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

I am trying to grep the output of a command that outputs unknown text and a directory per line. Below is an example of what I mean:

.MHuj.5.. /var/log/messages

The text and directory may be different from time to time or system to system. All I want to do though is be able to grep the directory out and send it to a variable.

I have looked around but cannot figure out how to grep to the end of a word. I know I can start the search phrase looking for a "/", but I don t know how to tell grep to stop at the end of the word, or if it will consider the next "/" a new word or not. The directories listed could change, so I can t assume the same amount of directories will be listed each time. In some cases, there will be multiple lines listed and each will have a directory list in it s output. Thanks for any help you can provide!

Answers

If your directory paths does not have spaces then you can do:

$ echo  .MHuj.5.. /var/log/messages  | awk  {print $NF} 
/var/log/messages

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/17622087/grep-from-beginning-of-found-word-to-end-of-word

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils