greenkillo.blogg.se

Cmd grep output file new lines
Cmd grep output file new lines





cmd grep output file new lines

#CMD GREP OUTPUT FILE NEW LINES INSTALL#

If you know the directory name is immediately preceded by the line's last occurrence of in followed by horizontal whitespace, you can use: set +HĬd "$(pip install django | grep -oP '\hin\h+(?!.*\hin\h.*)\K.*')" In contrast, we must match all the blanks after in, or they wouldn't be discarded by \K and they would be matched as part of the directory name. The pattern \h +in\h+\K.+ would have worked also, but we only need to look for one blank before in, regardless of how many are present. Look-around assertions are a feature of Perl regular expressions. +) that appear after a space or tab ( \h), in, and another one or more spaces or tabs ( \h+), without actually including in and the blank spaces surrounding it in the match. This uses a zero-width positive look-behind assertion ( \K) to match one or more characters (. If you know t he directory name is immediately preceded by in surrounded by horizontal whitespace (i.e., padded on both the left and the right with blanks), and that this is the only such occurrence of in on the line, you can use: cd "$(pip install django | grep -oP '\hin\h+\K.+')" This matches one or more ( +) of any character in a class of characters ( ) that is not ( ^) a space or tab ( \h). Here I've used a Perl regexp ( -P) because the \h abbreviation (for ) makes this easier to type and to read than an equivalent extended regexp ( -E). If you know the directory name contains no horizontal whitespace (no spaces or tabs) and appears at the end of the line, you can use: cd "$(pip install django | grep -oP '+$')" This matches a / followed by zero or more ( *) of any character (. If you know the directory name is absolute (i.e., starts with a /) and no / appears on the line before the directory name, you can use the same regexp as in heemayl's answer but with / instead of /usr: cd "$(pip install django | grep -o '/.*')" All the alternatives below still assume the directory name appears at the end of the line, but the other assumptions vary. Otherwise, you might choose a different regexp depending on what you know about the output being parsed. This is less typing even if you don't make use of tab completion.

cmd grep output file new lines

If the reason you know it starts with /usr is that you have just run the command and know the directory you want to change to, I suggest the simpler solution of running the command cd /usr/lib64/python2.7/site-packages.

cmd grep output file new lines

If you know the directory starts with /usr (and that it appears at the end of the line of output from pip, and that /usr does not appear anywhere on the line before the directory name), then that's a fine choice heemayl's answer tells you how. Depending on what you do and don't know beforehand about what pip will output, you might decide to grep for something other than /usr.*.







Cmd grep output file new lines