Tag Info

New answers tagged

1

To use ( (space+parenthesis) as field separator in awk, use " \\\(": $ echo "a (b (c" | awk -F " \\\(" '{ print $1; print $2; print $3 }' a b c Alternatively, use single quotes and two backslashes: $ echo "a (b (c" | awk -F ' \\(' '{ print $1; print $2; print $3 }' a b c The reason for this is that ( (a single parentesis with a leading space) is a ...


1

For this type of problems, it's usually best to start by breaking it into its constituent parts. Start with the innermost expression, which seems to aim to get all PIDs for myprocess in order to signal them, and work your way outwards, testing each step along the way to make sure it gives the output you expect. You are doing this by taking the output of ps, ...


0

Got it finally. I'm using Cygwin with Win7. The single quote marks were no good, so replacing ALL single quotes with double quotes fixed up the syntax, and additionally, "||" was no good, but "&&" works fine. So the following works: gawk -F "^" "{ if ($1 == $2 && $3 == $4 && $4 == $5 && $5 == $6) print 0; else print $1,$2,$3; ...


0

Try to avoid || and && For && test gawk -F "^" '$3 == $7{if($3 == $11){print "0"; next;}}{print $3,$7,$11}' For || test gawk -F "^" '$3 == $7{print "0"; next;}$3 == $11{print "0"; next;}{print $3,$7,$11}'


0

There are some good hints in this answer suggesting a path of least resistance using a scripting language like Perl, Python, Ruby, etc. which allows intermixing of mathematical and matching operations. Here is a quick hack with Perl: $ echo '2014-12-05 10:00:10, 1234, 2015-02-01 09:12:24' | perl -pe \ 's/(\d{4}-\d{2}-\d{2} ...


0

Just to clarify: vim is a system utility (a text editor) on most *nix systems. awk, sed, and bash are languages (or tools, depending on the context) that you can use to parse and alter text. What do you need to increment the time for, and how often will you need to increment it? Those factor into what tools you'll want to use. In any case, this is a ...


1

In general, using the shell for text-parsing is very slow and cumbersome. Here are some other options: Perl in "paragraph mode" perl -00pe 's/^/$./' file Explanation The -00 turns on paragraph mode where "lines" are defined by consecutive \n\n, paragraphs in other words. The s/^/$./ will replace the start of the line (^) with the current "line" ...



Top 50 recent answers are included