Tag Info

New answers tagged

12

The reason is that Invoker_Slark* is considered a regular expression where k* means: "zero or more occurrences of k" That's different from shell globbing patterns where * means 0 or more characters. To search for Invoker_Slark anywhere in the line, you need: grep 'Invoker_Slark' true_pairscore.txt or grep -x '.*Invoker_Slark.*' true_pairscore.txt If ...


2

You can't have a single quote inside single quotes, the ' in 'Danny closes the quotes. find . -type f -exec sed -e 's/'Danny'/'Danny Samuel'/g' -i.php '{}' + ^^ !!!!! ^ !!!!!!!!!!!! ^^ quoted quoted quoted unquoted unquoted Write it: find . -type f -exec ...


0

It's not clear whether you are trying to group lines by unknown output patterns or unknown keywords in known patterns. In the first case, if you have logs such as: [2010-04-02 12:00:00] Error: BaseController Something went wrong 2010-04-02 12:01:00 Warning - Something happened UserController (2010-04-02 12:02:00) failed with exit status: 1 [2010-04-02 ...


3

The following should work provided you don't have any underscores in the last part of any of the filenames (and nothing else in the directory that matches the glob): for file in ????_??_??_*.txt; do echo cat "$file" ">>""${file%_*}.txt" done Remove the echo part and the quotes around the >> when you are sure you have what you want.


0

GNU awk echo 'abc-1234-45' | awk --re-interval -v RS='[[:digit:]]{3,}' '{gsub(/[[:digit:]]/, "*", RT); printf "%s%s", $0, RT}' abc-****-45 Or if you are willing to look at Python echo 'abc-1234-45' | python -c 'import re; import sys; print re.sub(r"\d{3,}",\ lambda x: len(x.group())*"*", sys.stdin.readline().strip())'


3

You can use perl: $ echo "abc-1234-45" | perl -pe 's/(\d{3,})/"*" x length($1)/eg' abc-****-45 /e flag causes perl evaluate the right side as an expression before replacing.


0

Sample of fast(!) finding particular files (access_log) in multiple locations defined by wildcard (home directory) and general apache2 log directory applying also name filtering to exclude ssl logs and gzipped old logs. Does not directly answer the question here but might be userful for someone who found these instructions (like me). find / \( -path ...


2

I think what you are looking for is: grep -E '^.{15} pattern' This will be fine in most usage cases. However note that it won't 'match' just the pattern part, but everything before it will be included in the match too. You will see this by the highlighting of grep (if --color is given directly or has been included in a shell alias). Without colour, it ...


5

Ok, so I guess your problem was that multiple-quote marks per line were pulling in more than you wanted because regex is inherently greedy - it will always match as much as possible if it can. So the solution is to ensure you only match between the two double-quote marks, like: grep -o 'CLASS_NAME:"[^"]*"' script.js


2

The rules are different for single quotes versus double quotes. For the reason you show, double quotes can't be used reliably in bash, because there's no sane way to escape an exclamation mark. $ grep -oP "\\(.*(?!word).*right" bash: !word: event not found $ grep -oP "\\(.*(?\!word).*right" grep: unrecognized character after (? or (?- The second is ...


3

If you want to match from the second open parentheses up until (but not including) the next closing parentheses: grep -Po '\(.*?\K\([^)]*' Or portably with sed: sed -n 's/^[^(]*([^(]*\(([^)]*\).*/\1/p' To match the right most ( that is not followed by word up to the rightmost right after that: grep -Po '.*\K\((?!word).*right'


0

Look for the comma parens before and aft instead: grep -oP '(?<=,)\(.*(?=\),)' Example $ echo '(foo),(bar,baz(word,right),(end)' | grep -oP '(?<=,)\(.*(?=\),)' (bar,baz(word,right The lookahead and behind can only look for explicit strings, it cannot find things such as .*. References Lookahead and Lookbehind Zero-Length Assertions


2

You can do it with simple awk: $ echo '(foo),(bar,baz(word,right),(end)' | awk -F'),' '{print $2}' (bar,baz(word,right


5

To do this using POSIX basic regex, the closest I can come is: sed '/--Updated*[[:space:]][[:space:]]*Date/d' inputfile Unfortunately there is no real substitute for ?, so a * is used which would also match multiple ds. The + however can be replaced by simply repeating the pattern an using a * for the second repetition. Update Actually the way to get ...


2

With gnu sed 4.2.2 on cygwin, add the -r flag: '--Updated Date: 2013-11-06 15:32:13'|sed -r -e '/--Updated?[[:space:]]+Date/d' prints no output. -r turns on extended regular expressions so ? and + will work like you expect. The reference for extended regular expressions I use most points out that ? and + have to have a leading backslash in basic ...


5

you need to use the -r parameter. try use sed -r '/--Updated?[[:space:]]+Date/d' inputfile updating answer When you use sed '/something/d' , every line that match with this will be deleted. -r - the parameter -r is use extended regular expressions . Inside the expression have 2 regular expressions. [[:space:]] - Match with all whitespace characters, ...


1

You could use perl. The following performs a lexical comparison on the time field which implies that it'd work even if you don't have a line containing the starting or ending time. yourprogram | perl -lane 'print if $F[1] ge "08:25:00" and $F[1] lt "08:36:00"' This assumes that the time is the second field in your input and is of the form hh:mm:ss. You ...


2

With these inputs: 01/15 00:00:01 INFO: received connect request from 10.10.10.10 01/14 00:00:01 INFO: received connect request from 10.10.10.10 01/14 08:25:01 INFO: received connect request from 10.10.10.10 01/14 00:00:01 INFO: received connect request from 10.10.10.10 01/14 00:00:01 INFO: received connect request from 10.10.10.10 ...


1

If you are open to use sed, you can do : sed -n '/^01\/14 08:00/,/^01\/14 08:10/p' foo In general, you can use bash variables replace with the specific times in the above command. For example: st="01\/14 08:00" en="01\/14 08:25" sed -n "/^$st/,/^$en/p" foo #note the double quotes You need to escape the / character with a \ if using / as separator as ...


2

This should yield the desired result. egrep "08:[23]5:[0-5][0-9]" foo Using cat in this case is not needed.



Top 50 recent answers are included