43

The two are quite different. a[bc]d is a filename pattern (in shells other than fish). It will expand to the two filenames abd and acd if those are names of existing files in the current directory. The [...] part is a bracketed expression that matches a single character out of the ones listed (or collating elements when ranges are included). To match ...


11

Use a block in which you tell sed to only print when it sees C: sed -n '/EEE/,/FFF/{/C/p}'


10

check_prefixes () { value=$1 for prefix in aa abc 3@3; do case $value in "$prefix"*) return 0 esac done return 1 } check_contains_gt () { value=$1 case $value in *">"*) return 0 esac return 1 } var='aa>' if check_prefixes "$var" && check_contains_gt "$var"; then ...


8

Let's use tput to generate the color code for your terminal for yellow and black: $ yel=$(tput setaf 3) $ blk=$(tput setaf 0) Let's examine what the yellow code actually includes: $ echo -n "$yel" | hexdump -C 00000000 1b 5b 33 33 6d |.[33m| 00000005 Now, we can use grep to search for the yellow color code and print ...


7

a[bc]d is pattern-matching, and is part of the POSIX standard. In POSIX, this is introduced as the "pattern bracket expression". It is documented in section 2.13 of the manual When unquoted and outside a bracket expression, the following three characters shall have special meaning in the specification of patterns: ? A question-mark is a pattern ...


7

If you mean to search for a 256-bit number in hexadecimal form (64 chars from the range 0-9 and A-F -- one of the formats in which a bitcoin private key could appear), this should do: egrep -aro '\<[A-F0-9]{64}\>' files and dirs ... Add the -i option or also include the a-f range if some of the keys are in lowercase. For the general problem of ...


6

If you want to find all words of length 64 from /path/to/file, you can use tr -c '[:alnum:]' '\n' < /path/to/file | grep '^.\{64\}$' This replaces all non-alphanumeric characters by newlines, so each word is on its own line. Then it filters this result to include only the words of length 64.


6

For bash: Using the properties of regex you can write start with ^ and contain by nothing. The list of regexes to check start with aa abc or 3@3 and contains > is: ^aa ^abc ^3@3 > Make that a properly quoted list and ask bash to use regexes (=~): check_func() { matched=1 for test_regex in '^aa' '^abc' '^3@3' '>'; ...


5

@manatwork has it right, soundex is probably the tool you're looking for. Install the perl Soundex module using CPAN: $ sudo cpan Text::Soundex CPAN: Storable loaded ok (v2.27) .... Text::Soundex is up to date (3.04). Make a file full of names to test called names.txt jacob Jakob miguel Michael Now the perl script to use the Soundex module, soundslike....


5

FWIW here's a way to do it in perl, using max from List::Util $ perl -MList::Util=max -lpe '$_ .= " " . max 0, map length, /[CT]+/gi' file CACCGTTGCCAAACAATG 2 TTAGAAGCCTGTCAGCCT 3 CATTGCTCTCAGACCCAC 5 GATGTACGTCACATTAGA 2 ACACGGAATCTGCTTTTT 6 CAGAATTCCCAAAGATGG 5


4

$ awk '{ split($0, a, "[^CTct]+"); m=0 for (i in a) { len=length(a[i]) if (len > m) m=len } print $0, m }' file CACCGTTGCCAAACAATG 2 TTAGAAGCCTGTCAGCCT 3 CATTGCTCTCAGACCCAC 5 GATGTACGTCACATTAGA 2 ACACGGAATCTGCTTTTT 6 CAGAATTCCCAAAGATGG 5 This awk program splits each line on runs of anything that is ...


4

* in regular expressions means 0 or more of the preceding atom. You're confusing it with the * shell wildcard operator where it means 0 or more characters. OPENSSL_NO_* means OPENSSL_NO followed by 0 or more underscores. You'd want: grep -o 'OPENSSL_NO_.*' Where . is the regexp operator to match a single character. Or: grep -o 'OPENSSL_NO_[[:alnum:]]*' ...


4

You can try : sed '/EEE/,/FFF/!d;/C/!d'


4

Here's what the case statement does: take the second parameter to the function ($2). If it matches the pattern "$1"*, i.e. the first argument to the function followed by anything, then execute true and end the case statement. true does nothing and returns the status 0. Otherwise, if it matches *, i.e. anything, execute false and end the case statement. false ...


4

Revised based on clarification to the question: This is less elegant (and much less flexible), but more compact than the other answers, check_func() { case "$1" in ( aa* | abc* | 3@3* | *">"*) return 0 esac return 1 } This returns true for aardvark, abcdef, 3@3com.com and 12>5.  And, of course, ...


4

grep -x 'AFFX-KIT-000088' file The -x forces a match of a complete line. You may also want to add -F as you are matching with a string, not a regular expression. This would possibly speed up the operation. The -w option does not work here as - is not a "word character". The substring AFFX-KIT-000088 in AFFX-KIT-000088-A is therefore a complete word. "...


3

With sed (assuming no more than 19 characters per line), just for the fun of it and using the greedy properties of RE matching: sed ' h;y/cCtT/xxxx/;x;H;s/./x/g;G s/^\(x*\).*\n.*\1.*\n/\1 / s/^x\{10\}/1/;s/$/:9876543210xxxxxxxxx/ s/^\(1*\)\(x*\) \(.*\):.*\(.\).\{9\}\2$/\3 \1\4/' A variation on @Kusalananda's solution: awk -F '[^cCtT]+' ' { ...


3

Faster GNU awk solution: awk -v FPAT='[ctCT]+' \ '{ max_l = t_len = 0; for (i=1; i <= NF; i++) { len = length($i); if (len > max_l) max_l = len; t_len += len } print $0, t_len, max_l }' inputfile The output: CACCGTTGCCAAACAATG 9 2 TTAGAAGCCTGTCAGCCT 10 3 CATTGCTCTCAGACCCAC 12 5 GATGTACGTCACATTAGA 8 2 ...


3

If you have GNU grep (default on Linux), you can do: grep -Po '(^|\s)\S{64}(\s|$)' file The -P enables Perl Compatible Regular Expressions, which give us \b (word-boundaries) \S (non-whitespace) and {N} (find exactly N characters), and the -o means "print only the matching part of the line. Then, we look for stretches of non-whitespace that are exactly 64 ...


3

You can negate at the top level: if ! [[ …


3

Ignoring the header (which you can tack on later): awk -F, 'NR > 1 {print > $2}' use_rep which will print each line to a file named by the second column: ~ head *[0-9]* ==> 100K+ <== 86440,100K+ 116858,100K+ 22222,100K+ 38906,100K+ ==> 200K+ <== 22565,200K+ 7453,200K+ ==> 500K+ <== 885,500K+ ==> <100K <== 10762,<100K ...


3

You will have to search fist for search pattern, then sed, and log. try (line break for readability) find ./ -iregex '.*\.\(txt\|html\)$' \ -exec grep -q search {} \; \ -print \ -exec sed -i 's/search/replace/g' {} + \ > my-sed.log where search in -exec grep -q search {} \; is your search pattern. Note that you can't use + who will ...


3

Since sed knows it will have to apply a command to the final line of input, it can't output the most recently processed line until it's sure it can read more lines after that. You would not see the same behaviour in a sed editing script not using the $ address, as the transformation of the data does not depend on whether the current line is the final line ...


2

Via sed: sed 's/^../& /;s/[-()]/ /g' datafile.dat


2

I would actually do this with a shell loop: for dir in example.com/*; do prefix=${dir##*/} cp "$dir"/orm-mysql/build/conf/"$prefix"-conf.live.php \ example_dev.com/"$prefix"/orm-mysql/build/conf/$1-conf.live.php done That will complain if the target directory doesn't exist, but will work as expected if it does. If you want to avoid the ...


2

It seems that grep is the correct tool to "search" for an string. What is left to do is to define such string with a regex. The first issue is to define the limits of a word. It is not as simple as "an space", as a book, a lamp use , as word delimiter, in the same concept, many other characters, or even the start or end of a line could act as word delimiter. ...


2

I assume you mean by "from center" is "the sequence that includes the middle character of the string. I've added a line to the testing data such that the middle character of the string is neither a C or a T: $ cat file CCCCTGTTGCCAAACAATGC TTTTCCCGCCTTTGGCCTAC TACACGGAACCTCTTTTTTA CATAAAAAAAAAAAAACTCT The solution relies on awk's RSTART and RLENGTH ...


2

The * operator in regular expressions means "zero or more", so grep is perfectly happy to satisfy that condition by using "zero" additional characters. I would extend the regular expression in some way so that grep is forced to include the rest of the term: grep -o 'OPENSSL_NO_.*$' input or grep -o 'OPENSSL_NO_.*\b' input (where in both cases, I added ...


2

Using an awk script: NR == FNR { seq[++n] = $1; next } { header = $0 getline for (i = 1; i <= n; ++i) { if (match(seq[i], $0) > 0) { print header next } } print header print } Running it: $ awk -f script.awk file2 file1 1 GACGGAGGATGCAAGTGTTATCCGGAATCACTGGGCGTAAAGTTTTTTTTT 2 3 ...


2

With GNU awk: $ gawk -vFPAT='[A-Z]+|[a-z]' 'NF+=0' file AA MU i MU i j MU i N AB k AB k l AB k N MB k i MB k l i MB k l i j MB k l i N MB k N i j MB k N i N Note that will skip empty lines, since it relies on a non-zero side-effect value of NF+=0 to trigger the default print; if that's undesirable, you can use the slightly more verbose {NF+=0} 1.


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