How can I format the output of a bash command in neat columns

column(1) is your friend. $ column -t <<< ‘”option-y” yank-pop > “option-z” execute-last-named-cmd > “option-|” vi-goto-column > “option-~” _bash_complete-word > “option-control-?” backward-kill-word > “control-_” undo > “control-?” backward-delete-char > ‘ “option-y” yank-pop “option-z” execute-last-named-cmd “option-|” vi-goto-column “option-~” _bash_complete-word “option-control-?” backward-kill-word “control-_” undo “control-?” backward-delete-char

How to print 5 consecutive lines after a pattern in file using awk [duplicate]

Another way to do it in AWK: awk ‘/PATTERN/ {for(i=1; i<=5; i++) {getline; print}}’ inputfile in sed: sed -n ‘/PATTERN/{n;p;n;p;n;p;n;p;n;p}’ inputfile in GNU sed: sed -n ‘/PATTERN/,+7p’ inputfile or sed -n ‘1{x;s/.*/####/;x};/PATTERN/{:a;n;p;x;s/.//;ta;q}’ inputfile The # characters represent a counter. Use one fewer than the number of lines you want to output.

How to delete rows from a csv file based on a list values from another file?

What about the following: awk -F, ‘(NR==FNR){a[$1];next}!($1 in a)’ blacklist.csv candidates.csv How does this work? An awk program is a series of pattern-action pairs, written as: condition { action } condition { action } … where condition is typically an expression and action a series of commands. Here, the first condition-action pairs read: (NR==FNR){a[$1];next} if … Read more

Sum duplicate row values with awk

Use an Awk as below, awk ‘{ seen[$1] += $2 } END { for (i in seen) print i, seen[i] }’ file1 1486113768 9936 1486113769 6160736 1486113770 5122176 1486113772 4096832 1486113773 9229920 1486113774 8568888 {seen[$1]+=$2} creates a hash-map with the $1 being treated as the index value and the sum is incremented only for those … Read more

Awk replace a column with its hash value

So, you don’t really want to be doing this with awk. Any of the popular high-level scripting languages — Perl, Python, Ruby, etc. — would do this in a way that was simpler and more robust. Having said that, something like this will work. Given input like this: this is a test (E.g., a row … Read more