Getting rid of a field in a big file - Urgent

Hi Unix Gurus,

I have a file with 100,000 lines with lines in the format:

1,35518,35518,1,2,1,72,1253889535,1253889775,240,30,152.163.141.8,US,0,00,-g 1253888723-g 1253889445
1,78973,78973,1,2,2,91,1253889535,1253889775,240,30,152.163.141.8,US,0,00,-g 1253888723-g 1253889445
1,82108,82108,1,2,1,402,1253889535,1253889775,240,30,152.163.141.8,US,0,00,-g 1253888723-g 1253889445
1,83406,83406,1,2,1,1684,1253889535,1253889775,240,30,152.163.141.8,US,0,00,-g 1253888723-g 1253889445
1,89373,89373,1,2,1,402,1253889535,1253889775,240,30,152.163.141.8,US,0,00,-g 1253888723-g 1253889445
1,90924,90924,1,2,2,402,1253889535,1253889775,240,30,152.163.141.8,US,0,00,-g 1253888723-g 1253889445
1,91225,91225,1,2,5,1119,1253889535,1253889775,240,30,152.163.141.8,US,0,00,-g 1253888723-g 1253889445
1,91721,91721,1,2,1,3305,1253889535,1253889775,240,30,152.163.141.8,US,0,00,-g 1253888723-g 1253889445
1,94631,94631,1,2,6,402,1253889535,1253889775,240,30,152.163.141.8,US,0,00,-g 1253888723-g 1253889445
1,102766,102766,1,2,6,1119,1253889535,1253889775,240,30,152.163.141.8,US,0,00,-g 1253888723-g 1253889445

I need to get rid of the part "1253888723-g" from every line. Basically in the last field of every line, "-g 1253888723-g 1253889445" I need to get rid of the center part which is "1253888723-g" and have the last field like this: "-g 1253889445" . Is there any easy way of doing this using perl or awk. Please help me out. Your help is really appreciated.

Thanks,
Toms

sed -i.bak 's/-g [0-9]\{10\}//' your_bigFile

assuming the field is always '-g followed by 10 digits'.
This will also keep a copy of your file at your_bigFile.bak.

Thanks a lot for your quick response. That seemed to work pretty well :slight_smile:

I would also like to get a solution to actually get rid of the entire last field including the last comma from every line. Basically the entire field ",-g 1253888723-g 1253889445"

Toms

sed 's/\(.*\),.*$/\1/'