Assigning system command’s output to variable

Note: Coprocess is GNU awk specific. Anyway another alternative is using getline cmd = “strip “$1 while ( ( cmd | getline result ) > 0 ) { print result } close(cmd) Calling close(cmd) will prevent awk to throw this error after a number of calls : fatal: cannot open pipe `…’ (Too many open files)

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

Remove all text before colon

Here are two ways of doing it in R: foo <- “TF_list_to_test10004/Nus_k0.345_t0.1_e0.1.adj:PKMYT1” # Remove all before and up to “:”: gsub(“.*:”,””,foo) # Extract everything behind “:”: regmatches(foo,gregexpr(“(?<=:).*”,foo,perl=TRUE))

Convert date formats in bash

#since this was yesterday date -dyesterday +%Y%m%d #more precise, and more recommended date -d’27 JUN 2011′ +%Y%m%d #assuming this is similar to yesterdays `date` question from you #http://stackoverflow.com/q/6497525/638649 date -d’last-monday’ +%Y%m%d #going on @seth’s comment you could do this DATE=”27 jun 2011″; date -d”$DATE” +%Y%m%d #or a method to read it from stdin read -p … Read more

Can we use shell variables in awk?

Yes, you can use the shell variables inside awk. There are a bunch of ways of doing it, but my favorite is to define a variable with the -v flag: $ echo | awk -v my_var=4 ‘{print “My var is ” my_var}’ My var is 4 Just pass the environment variable as a parameter to … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)