linux - Awk: Remove text after last space in row -


i have tab-delimited text file in following format.

col1  | col2  | col3 123.0 | 534.2 | blah0 2031/23/12 23.00 | 786.2 | blah1 2033/01/01 12.40 | 343.0 | blah2 2031/27/11 

i need remove characters after space last column. output be

col1  | col2  | col3 123.0 | 534.2 | blah0 23.00 | 786.2 | blah1 12.40 | 343.0 | blah2 

how should go using awk or similar?

with awk:

awk -f '\t' 'begin { ofs = fs } nr != 1 { sub(/ [^ ]*$/, "", $nf) } 1' filename 

that is:

begin { ofs = fs }           # output should separated same way                              # input  nr != 1 {                    # in lines except header line:   sub(/ [^ ]*$/, "", $nf)    # replace last space , after }                            # in last field ($nf)  empty string                              # (i.e., remove it)  1                            # in lines: print. 

if there can several spaces in last field , want remove after first space, use sub(/ .*/, "", $nf) instead. wasn't entirely clear in question should happen in such case.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -