Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

awk: how to delete first and last value on entire column

Tags:

awk

I have a data that is comprised of several columns. On one column I would like to delete two commas that are each located in beginning and the end of entire column. My data looks something like this:

a    ,3,4,3,2,
b    ,3,4,5,1,
c    ,1,5,2,4,5,
d    ,3,6,24,62,3,54,

Can someone teach me how to delete the first and last commas on this data? I would appreciate it.

like image 732
user3546860 Avatar asked Jan 23 '26 02:01

user3546860


1 Answers

$ awk '{gsub(/^,|,$/,"",$NF)}1' file
a 3,4,3,2
b 3,4,5,1
c 1,5,2,4,5
d 3,6,24,62,3,54
like image 85
Ed Morton Avatar answered Jan 25 '26 17:01

Ed Morton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!