Tag Info

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


7

I'd use find to locate the files and pipe the result through xargs: $ find . -type f \! -name "*~" \ \! -name "*.map" \ \! \( -name "*.js" -and \! -name "*.debug.js" \) \ -print0 | xargs -0 grep "OK" This searches for every file not matching "*~", "*.map" or "*.js but not *.debug.js". Using find you can easily ...


6

In addition to your question please note that .rar does not only match ".rar" but matches every single character (including .) before the rar. In this case probably not a problem but . must be escaped in regexes. ls -R | grep "\.rar$"


5

All you need is a simple grep: grep -Fwf gene_list.txt gene_info.txt The options used are: -w : Search for whole words, this ensures that the gene name ERK1 will not match the gene ERK12 (-w is not a standard option but is fairly common) -f : Read the patterns to be searched for from a file. In this case gene_list.txt. -F : Treat the patterns as ...


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


5

Using awk: awk '{print $NF}' inputfile For your sample input, it'd produce: ant tiger rabbit lion monkey donkey Using GNU grep: grep -oP '\S+$' inputfile Using sed: sed 's/.* //' inputfile Using perl: perl -pe 's/.* //' inputfile


5

I would just pass that through a second grep to remove them: grep -r --exclude={\*~,\*.map} "OK" bar/ | grep -vP '(?<!debug)\.js' The -v reverses the match, printing lines that don't match the pattern and the -P enables Perl Compatible Regular Expressions which let us use negative lookbehinds. This particular regex, will match .js that is not ...


4

You generally don't want to remove packages like this in pieces since there's typically dependencies that you're skipping over. Better to do this removal all at once like so: $ rpm -e $(rpm -aq | grep php) Better still I would encourage you to use yum to do this vs. RPM. $ yum remove $(rpm -aq | grep php) Even better then these would be to figure out a ...


4

From an example on the awk wiki: awk 'FNR==NR {arr[$0];next} $6 in arr' gene_list info_list Explanation copied from the wiki entry: FNR == NR: This test is true when the number of records is equal to the number of records in the file. This is only true for the first file, for the second file NR will be equal to the number of lines of file1 + FNR. ...


4

With pcregrep: pcregrep -rMl '^C.*\nC' . POSIXly: find . -type f -exec awk ' FNR==1 {last=0; printed=0; next} printed {next} /^C/ {if (last) {print FILENAME; printed=1; nextfile} else last=1; next} {last=0}' {} + (though that means reading all the files fully with those awk implementations that don't support nextfile). With versions of GNU ...


4

cat file.txt | grep -o -P '.{0,20}string.{0,20}' This should do it for you Update: If you don't want to cat, you can just use the grep with the file as a parameter: grep -o -P '.{0,20}pseudomonas.{0,20}' FileName.html Hope it helps Also, The -P uses Perl Regex, which the man pages says is experimental, if you want to avoid that flag, you could just ...


4

You can use awk for this: awk '/^2009/{a=$0;next}{print a" "$0} ' file.txt This will only prepend a space to any lines before the first match of 2009, you can set a default string to prepend like this: awk 'BEGIN{a="My default prepend string";}/^2009/{a=$0;next}{print a" "$0} ' file.txt


3

\< matches the beginning of a word \> matches the end of a word \b matches both boundaries if at the end or at the beginning The important thing about those special characters is that they match an empty string and not the word boundary itself. a word boundary being the contrary of the the set of character represented by \w equivalent of ...


3

pcregrep -MnirIso '(?s).{0,20}pseudomonas.{0,20}' . | grep --color -e '^' -e pseudomonas Assumes matches and their context don't overlap and that filenames don't contain pseudomonas. Also note that the reported line numbers are those of the beginning of the context.


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

This should probably work awk '/^2009/{Prepend = $0; next} {print Prepend, $0}' file.txt So output looks like: awk '/^2009/{Prepend = $0; next} {print Prepend, $0}' file.txt 2009 150 0 0 0 0000 75.316 0.0400390625 0.00007 0.00000 0.8980 2009 150 0 0 0 0000 76.216 0.0400390625 0.00007 1.00000 0.9046 2009 150 0 0 0 ...


3

I'd do this in Perl: perl -lne 'if(/^2009/){$n=$_; next} print "$n $_"' file or, more concisely perl -lne '/^2009/ ? ($n=$_) : print "$n $_"' file The idea is to save the current line ($_ in Perl) as $n if it begins with 2009 and if not, print the current line along with the current value of $n.


3

With zsh you can do: grep OK some/dir/**/^(*~|*.map|(^*debug).js) Provided of course the argument list isn't too long, in which case you can always do: printf '%s\0' some/dir/**/^(*~|*.map|(^*debug).js) | xargs -0 grep ok


3

You'll want to do something more like this: for i in $(cat /tmp/10218.after) do grep $(echo ${i} | cut -f1) /tmp/10218.before done If you want to get a bit more fancy and output something if the grep fails you cand do something like: for i in $(cat /tmp/10218.after) do COUNT=grep -c $(echo ${i} | cut -f1) /tmp/10218.before if [[ ${COUNT} ...


3

In bash while read -r word do grep -q "$word" file.before if [ $? -ne "0" ] then echo "$word not in file" fi done < <(cut -f1 -d" " file.after) The -q to grep tells it to be quiet, you can then interrogate $? to see if there was a match 0 or not 1.


2

With awk: awk '{if (p ~ /^C/ && $1 ~ /^C/) print; p=$1}' afile.txt This will print contents of the file if there are consecutive lines starting with a C. The expression (p ~ /^C/ && $1 ~ /^C/) will look into successive lines in the file and will evaluate to true if the first character in both match C. If that is the case, the line will be ...


2

For more robustness you could alter the gene list into regular expressions to match at the end of the line. This should work (and be POSIX compatible): sed 's/[[:space:]]*$/[[:space:]]*$/' gene_list | grep -wf - gene_info Or with leading space in the gene_list (as per the example in the question): sed 's/$/[[:space:]]*$/; s/[[:space:]]//' gene_list | ...


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


2

ls | grep -oP "(?<=$study.)[A-Z]$" will return any uppercase letter that is preceded by the contents of $study plus one arbitrary character (the T in your example) and followed by the end of the line. The -P option (Perl regular expressions) is needed to be able to use the positive lookbehind expression (?<=...), but might not be available on every ...


2

Yet another option with GNU sed: For a single file: sed -n -- '/^C/{n;/^C/q 1}' "$file" || printf '%s\n' "$file" (though it will also report the files it cannot read). For find: find . -type f ! -exec sed -n '/^C/{n;/^C/q 1}' {} \; -print The problem with unreadable files being printed can be avoided by writing it: find . -type f -size +2c -exec sed ...


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

The closest you can come to finding when a file was last executed is by its atime rather than modification time - executing does not modify the files. However, there is no way to tell if the file was accessed for some other reason. Although, if a file hasn't been accessed within a specific time frame, then it can't have been executed. To list executable ...


2

I don't think you need to use wget's recursive downloading options because you already have a list of the files that need downloading: wget --input-file=./path/to/your/list --base=URL In this way you would just follow the list in the first place, and so every file downloaded would be just the next in the list. So you could always find your progress by ...


2

You can do this with comm (using bash process substitution): comm -13 <(find / | sort) <(sort server_dump) This will show the files which are unique to the server. For files that are unique to the local system: comm -23 <(find / | sort) <(sort server_dump) You may also wan to add the -xdev option to find to stop it from comparing files on ...


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



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