2021-04-23


Example of .bashrc commands (No.1)


In my .bashrc file, I have the following set of aliases: 

alias  pcol1="awk '{print \$1}'"

alias  pcol2="awk '{print \$2}'"

alias  pcol3="awk '{print \$3}'"

alias  pcol4="awk '{print \$4}'"

alias  pcol5="awk '{print \$5}'"

alias  pcol6="awk '{print \$6}'"

alias  pcol7="awk '{print \$7}'"

alias  pcol8="awk '{print \$8}'"

alias  pcol9="awk '{print \$9}'"

alias pcol10="awk '{print \$10}'"

alias pcol11="awk '{print \$11}'"

alias pcol12="awk '{print \$12}'"

(Full disclosure: I am not cool enough to have invented these on my own. Credit is due to someone else on the internet; but it's been a long time and I don't remember where I found these anymore.)

Suppose you have a data file (or output from some command) that looks like this: 

<tryan1@iMac:/home/>$ cat data.txt

400     37.4            52.5               -15.1

425     100.2           124.2              -24.0

450     226.2           251.5              -25.3

475     451.1           504.6              -53.5

500     821.6           877.9              -56.3

525     1397.4          1486.1             -88.7

550     2253.8          2377.7            -123.9

575     3483.7          3613.3            -129.6

600     5199.8          5335.0            -135.2

625     7536.7          7607.1             -70.4

Using the pcol* aliases I've set in my .bashrc, I can isolate, for example, the 3rd column only with this simple command: 

<tryan1@iMac:/home/>$ cat data.txt | pcol3

52.5

124.2

251.5

504.6

877.9

1486.1

2377.7

3613.3

5335.0

7607.1