New answers tagged

1

Another option is to be more specific about what you are grepping for. For example: whois stackoverflow.com | grep -E '^[[:space:]]*(Registr(ar|ant|y)|Sponsoring).*: ' This extracts only lines that begin with optional white space before either 'Registrar', 'Registrant', 'Registry', or 'Sponsoring', followed by any number (zero or more) of any character, ...


0

You only provided one example. More would be nice! Any.Series.S01E01.VOSTFR.@whatever.com.avi Which you want broken up into: Any Series S01 E01 VOSTFR avi At first glance, this isn't too dissimilar to the problem of RPM package naming, where the first field (name) can contain the delimiter used elsewhere. However, I'm going to assume you have a fixed ...


2

Use the -v flag: reg=`whois stackoverflow.com | egrep -i 'Registrar|Sponsoring Registrar|Registrant' | grep -v internic`


1

POSIX shell script: inp="${domain#http*://}" Test: for domain in 'https://foo.bar/baz' 'http://foo.bar/baz' ; do \ inp="${domain#http*://}" ; \ echo "$inp" ; \ done Output: foo.bar/baz foo.bar/baz


1

Besides running twice: Using extended glob: shopt -s extglob v=${domain#http?(s)://} printf "%s\n" "$v" Using bash internal variable BASH_REMATCH: Requiring protocol: if [[ "$domain" =~ https?://(.*) ]] then printf "%s\n" "${BASH_REMATCH[1]}" else printf "Not valid input: '%s'\n" "$domain" fi Not requiring protocol: [[ "$domain" =~ ...


1

Just do it twice: inp="${domain//http:'//'}" inp="${inp//https:'//'}"


4

The entire format string is to be preceded by the +: $ date +"So this is week: %U" So this is week: 19 $ date +"So this is week: %U of %Y" So this is week: 19 of 2016


1

perl -00 -n -e 'print if (m/blue/i && m/green/i && m/yellow/i)' filename This uses perl's paragraph-reading mode (-00) to print only paragraphs containing all three words (with case-insensitive matches). a 'paragraph' is one or more lines of text, separated from other paragraphs by at least one blank line. e.g. I saved the text of your ...


0

Or with awk, using the regexp <|> as the field delimiter: $ echo "<xml:attribute>{41c33a-4893b-3627a-617a}</xml:attribute>" | awk -F '<|>' '{print $3}' {41c33a-4893b-3627a-617a} Note: tested with GNU awk, mawk, and original-awk. Works the same in all three. The perl version is very similar (except perl arrays are ...


0

You can also have sed extract the field specified by a regular expression. Useful if you have more complex matching criteria: echo '<xml:attribute>{41c33a-4893b-3627a-617a}</xml:attribute>' | \ sed -E 's/^.+>({.+})<.+$/\1/'


1

For simple string manipulations, you should generally use the shell's own constructs, tied to parameter expansion. External utilities are better at processing large volumes of text, but for a single string, launching an external tool is slow and getting the quoting right can be difficult. ...


2

You can use cut's -d option to define a delimiter (which is excluded from the resulting fields): echo "<xml:attribute>{41c33a-4893b-3627a-617a}</xml:attribute>" | cut -d\> -f2 | cut -d\< -f1 This splits on > and outputs the second field, leaving {41c33a-4893b-3627a-617a}</xml:attribute, then again on < and outputs the first ...



Top 50 recent answers are included