Search code examples
bashawkcut

applying cut a second time to specific field/column in bash


I'm trying to display part of the content of a file. I currently use the following code to cut and format the fields I'm interested in

CONTENT="(cat foo.dat | cut -d ' ' -f 1,4,5)"
TOPRINT=$(printf "%7s  %10s  %14s\n" $(eval $CONTENT))

Now my problem is I would like to further edit the 5th field that looks like

bla=0.,bleh=2.,name=hello_im_here

as the only part I want to display is the name ("hello_im_here"). I'm guessing I could use awk (as is done in cut string in a specific column in bash) but as I'm not at all familiar with this command, I would appreciate more specific input on this. Thanks in advance.


Solution

  • could you try this;

    #!/bin/bash
    CONTENT=$(awk '{gsub(" *.*=","",$5); printf "%7s  %10s  %14s\n",$1,$4,$5}' foo.dat)
    echo $CONTENT