1837523 Members
3750 Online
110117 Solutions
New Discussion

how to "cut"

 
SOLVED
Go to solution
Lai Nee Shyang_1
Frequent Advisor

how to "cut"

Hi there

I'm writing a script to cut a couple of strings of varing size ending with "_xx" where xx is a number. Example : abc_def_12, ghi_jkl_mno_pqr_34, xyz_56"

I know cut can do delimiter follow by field number "cut -d _ -f 1", how do I specify the last field after the "_" delimiter.

Thanks

Lai

: )
If it doesn't work, We'll make it work. If it works, We'll make it work better.
2 REPLIES 2
Robin Wakefield
Honored Contributor
Solution

Re: how to "cut"

Hi Lai,

cut can only reference forwards. I'd use:

awk -F_ '{print $NF}'

Rgds, Robin
Stefan Schulz
Honored Contributor

Re: how to "cut"

I can't think of a way to do this with cut, but its pretty easy with awk:

awk -F_ '{print $NF}'

Hope this helps

Regards Stefan
No Mouse found. System halted. Press Mousebutton to continue.