Searching for a file in all Git branches
This is one way: git log –all –name-only –pretty=format: | sort -u | grep _robot.php
This is one way: git log –all –name-only –pretty=format: | sort -u | grep _robot.php
You can quote the pattern: grep -r –exclude=”*.cmd” “ckim” ./ PS. ./ is the current directory
Using grep -oP: s=”<some text> [email protected], <some text>” grep -oP ‘(?<=from=).*?(?=,)’ <<< “$s” [email protected] OR else avoid lookbehind by using \K: grep -oP ‘from=\K.*?(?=,)’ <<< “$s” [email protected] In case your grep doesn’t support -P (PCRE) use this sed: sed ‘s/.*from=\(.*\),.*/\1/’ <<< “$s” [email protected]
Try this: grep -rl <string-to-match> | xargs grep -L <string-not-to-match> Explanation: grep -lr makes grep recursively (r) output a list (l) of all files that contain <string-to-match>. xargs loops over these files, calling grep -L on each one of them. grep -L will only output the filename when the file does not contain <string-not-to-match>.
Pipe | any output to: sed G Example: ls | sed G If you man sed you will see G Append’s a newline character followed by the contents of the hold space to the pattern space.
You can use awk: awk ‘{print $1}’ your_file This will “print” the first column ($1) in your_file.
Maybe you want git ls-files which lists the files in the index? (and automatically adjusts for your current directory inside the git work directory)
Use sed? sed -e “s/\(.*\)/’\1″https://stackoverflow.com/” Or, as commented below, if the directories might contain apostrophes (nightmare if they do) use this alternate sed -e “s/”https://stackoverflow.com/”\\\\”/g;s/\(.*\)/’\1″https://stackoverflow.com/”
I’m not sure if I got your question right, so here are some shots in the dark: Print last occurence of x (regex): grep x file | tail -1 Alternatively: tac file | grep -m1 x Print file from first matching line to end: awk ‘/x/{flag = 1}; flag’ file Print file from last matching … Read more
This question was asked ten years ago, so I won’t mark it as duplicate. Also I noticed no sed solution was given since OP asked an answer without: sed -nr ‘s/(hello[0-9]+), please match me/\1/p’ test.txt -n stands for quiet (won’t print anything except if explicitly asked) -r allows use of extented regular expressions (avoids here … Read more