linuxawkcut

Using AWK with multiple delimiters


I'm trying to get the first part of Column $1 with the entire Column $2,$3 and $5 but unfortunately I'm getting a different output

Input:

2023-08-01 05:30:01,Lakers,CA,LA,US
2023-10-05 16:40:23,Denver Nuggets,CO,DN,US
2024-01-20 16:40:23,Utah Jazz,UT,SLC,US

Expected output

2023-08-01,Lakers,CA,US

cut -d, -f1,2,3,5

awk -F',' '{ print $1,$2,$3,$5 }'

Solution

  • This may be what you want, using any awk, but without expected output in the question it's a guess:

    $ awk 'BEGIN{FS=OFS=","} {sub(/ [^,]+/,""); print $1, $2, $3, $5}' file
    2023-08-01,Lakers,CA,US
    2023-10-05,Denver Nuggets,CO,US
    2024-01-20,Utah Jazz,UT,US