Posts

Showing posts with the label Awk

Better Way Of Getting A GIT Commit Message By Short Hash?

Answer : git log takes (among other things): -n num to limit the number of commits shown: choose 1 (and if num is 9 or less you can just write - num , hence, -1 , for short) --pretty=format: string with directives to change the log output format. The %s directive gets the commit "subject", which is what you also get with oneline . Hence: git log -n 1 --pretty=format:%s $hash (or git log -1 --pretty=format:%s ) will do the trick here. For a complete list of format directives, see the git log documentation, under "PRETTY FORMATS" (about halfway down). Depending on how much of the commit message you actually want, there are several pretty-format specifiers that you can use: · %s: subject · %f: sanitized subject line, suitable for a filename · %b: body · %B: raw body (unwrapped subject and body) So something like git log -1 --pretty=format:%b <hash> , or use one of the other specifiers (I think %s is probably cl...

Awk + Print All Line Content Except $1

Answer : If you set $1 to "" you will leave the delimiting space. If you don't want to do that you have to iterate over the fields: awk '{for (f=2; f<=NF; ++f) { if (f!=2) {printf("%s",OFS);} printf("%s",$f)}; printf "\n" }' Edit: fixed per Gilles' comment. Another way to do the same thing: awk '{d = ""; for (f=2; f<=NF; ++f) {printf("%s%s", d, $f); d = OFS}; printf("\n") }' Somehow I think this would be so much easier and more intuitive to do with the cut command: echo /var/sysconfig/network/my_functions alpha beta gama | cut -d' ' -f 2- The only problem is that cut doesn't support multiple different types of whitespace at once for delimiters. So if you have spaces or tabs, it won't work.