New answers tagged regular-expression
0
There is always a way. The given problem can be solved fairly easily by using commas as separator.
echo "@article{gjn2010jucs, Author = {Grzegorz J. Nalepa}, " |
awk -F, '{sub(/^[ \t]/, "", $2); print $2}'
When the numbers of fields vary something slightly better is usually needed. In such case finding a stop words often pays off, as you can cut ...
1
You're probably in a UTF-8 locale (check the output of locale charmap).
Use:
LC_ALL=C gawk '/\x56\x69\x72\x75\x73\xb4/ { print "Match!" }' virus.com
to make sure byte and character mean the same thing.
1
Ok, after several tries I sorted this up:
rsync -vaiz --delete --exclude=.svn/ --include='*.php' --include='*.js' \
--include='*/' --exclude='*' --prune-empty-dirs \
--filter "protect .svn/" /origin /destination
Thank you
1
1st attempt (didn't work)
You need to include the directories in addition to the files:
rsync -zavC --delete --include '*/' --include='*.php' --include='*.js' \
--exclude="*" /media/datacod/Test/ /home/lucas/Desktop/rsync/
2nd attempt
rsync -avzC --filter='-rs_*/.svn*' --include="*/" --include='*.js' \
--include='*.php' --exclude="*" --delete ...
1
I am not sure what you want to do with the files after you find them, but for interactive use in zsh I would use something like this:
ls **/trunk/**/config/*.xml
6
That's not a regex. For globs one should use the -path predicate instead.
0
perl -lane 'print "($F[07]):" eq "$F[8]" ? "@F[0..7]:" : "@F"'
This Perl one liner will split the string on spaces, so following string will be split into 9 parts:
On dd mmm yyyy hh:mm +hhmm, from info@example.org (info@example.org):
It will compare part8 (e-mail address) with part9 (senders name) and if they are same then part8 will be removed. leaving ...
2
grep '^[dD][aeiou]..s$' /usr/share/dict/words
^[dD] - match d or D at the beginning of the line
[aeiou] - match a, e, i, o or u
.. - match any two characters
s$ - match s, followed by the end of the line
1
if expr ".$IP_ADDRESS" : '\(\.[0-9]\{1,3\}\)\{3,4\}$' > /dev/null
then echo match
else echo no match
fi
You can't use grep here because grep is used to match lines, not strings. You can't use echo either as it does substitutions on its arguments. You can't leave variables unquoted either as otherwise filename generation and word splitting occurs.
...
0
This should do it:
echo $IP_ADDRESS | grep -Eo '([0-9]{1,3}\.[0-9]{1,3}(\.[0-9]{1,3}){1,2})'
or using the named sets:
echo $IP_ADDRESS | grep -Eo '([[:digit:]]{1,3}\.[[:digit:]]{1,3}(\.[[:digit:]]{1,3}){1,2})'
Examples
# 4 octets
$ echo '10.10.0.1' | grep -Eo '([0-9]{1,3}\.[0-9]{1,3}(\.[0-9]{1,3}){1,2})'
10.10.0.1
# 3 octets
$ echo '10.10.0' | grep ...
2
You need grep -q. If you don't distinguish between more exit codes than "0" and "other" there is no need to seperate grep and if:
if grep -q "^${uzer}:" /etc/passwd; then
echo "User does exist :)"
else
echo "No such user"
fi
3
-c means that you want to know the number of times this user is in /etc/passwd, while $? is the exit code. Those are differents, since the number of times is printed on stdout. Use $() for getting stdout into a variable
Second problem: all your variables, like $uzer will not be substituted with their values when in single quotes. Use double quotes.
...
4
The field separator of the split function is a regular expression, so you can split on = OR ;. If you know that $9 begins with "ID=", then
awk -v OFS='\t' '
$3 == "gene" {
split($9, id, /[=;]/)
print $1, $4, $5, id[2], $6, $7
}
' genes.gff3
If "ID=" is not necessarily at the beginning of the field, then there's a little more work ...
2
This is a Bash solution, as allowed me to publish, despite the explicit request asking to use awk and sed:
show_genes()
{
local filename="$1"
while read -ra larr; do
if [[ ${larr[2]} = gene ]]; then
larr[8]="${larr[8]%%;*}"
larr[8]="${larr[8]#ID=}"
printf '%s\n' "${larr[*]}"
fi
done < ...
1
You could split the field and use substr by:
split($9, a, ";")
print substr(a[1], 4)
Awk indexes start at 1.
Another option could be to modify the input field separator (FS).
FS is space, " ", by default – which also has the special effect of ignoring
leading and trailing spaces.
Also, instead of using print $1, \t, ... or the printf variant one could
...
Top 50 recent answers are included




