I am trying to echo all fields except for the last field.
I want to include the field seperator, but it is removed.
echo "a;s;v;g" | awk -F ";" '{$(NF--)=""; print}'
a s v
I want an output like this:
a;s;v;
I am trying to echo all fields except for the last field.
I want to include the field seperator, but it is removed.
echo "a;s;v;g" | awk -F ";" '{$(NF--)=""; print}'
a s v
I want an output like this:
a;s;v;
echo "a;s;v;g" | awk 'BEGIN{FS=OFS=";"}{$(NF--)=""; print}'
Using shell parameter expansion
var="a;s;v;g"
echo ${var%;*}
or awk
echo "a;s;v;g" | awk -F ";" '{$(NF--)=""}1' OFS=\;
or sed
echo "a;s;v;g" | awk -F ";" '{$(NF--)=""; print}' | sed "s/\ /;/g"