Tag Info

Hot answers tagged

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, ...


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 ...


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


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'


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.


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 ...


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 ...


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 ...


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

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 ...


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 ...



Only top voted, non community-wiki answers of a minimum length are eligible