Question related to sed or awk or perl

Hi All,

I have a big file of 100,000 lines with the following format:

1,736870,736870,1,2,5,547,1253889535,1253889775,240,30,152.163.141.8,US,0,00,-g 1253889445
1,881246,881246,1,2,6,402,1253889535,1253889775,240,30,152.163.141.8,US,0,00,-g 1253889445
1,975311,975311,1,2,6,72,1253889535,1253889775,240,30,152.163.141.8,US,0,00,-g 1253889445
1,1003112,1003112,1,2,2,93,1253889535,1253889775,240,30,152.163.141.8,US,0,00,-g 1253889445
1,1013824,1013824,1,2,5,547,1253889535,1253889775,240,30,152.163.141.8,US,0,00,-g 1253889445
1,1014543,1014543,1,2,3,72,1253889535,1253889775,240,30,152.163.141.8,US,0,00,-g 1253889445
1,1016002,1016002,1,2,6,878,1253889535,1253889775,240,30,152.163.141.8,US,0,00,-g 1253889445
1,1023369,1023369,1,2,1,1,1253889535,1253889775,240,30,152.163.141.8,US,0,00,-g 1253889445
1,1026987,1026987,1,2,6,72,1253889535,1253889775,240,30,152.163.141.8,US,0,00,-g 1253889445

I would like to get rid of the last field in all the lines. Basically I need a file without the last field "-g 1253889445" in every line.

The output file should look like this:

1,736870,736870,1,2,5,547,1253889535,1253889775,240,30,152.163.141.8,US,0,00,
1,881246,881246,1,2,6,402,1253889535,1253889775,240,30,152.163.141.8,US,0,00,
1,975311,975311,1,2,6,72,1253889535,1253889775,240,30,152.163.141.8,US,0,00,
1,1003112,1003112,1,2,2,93,1253889535,1253889775,240,30,152.163.141.8,US,0,00,
1,1013824,1013824,1,2,5,547,1253889535,1253889775,240,30,152.163.141.8,US,0,00, 
1,1014543,1014543,1,2,3,72,1253889535,1253889775,240,30,152.163.141.8,US,0,00,
1,1016002,1016002,1,2,6,878,1253889535,1253889775,240,30,152.163.141.8,US,0,00,
1,1023369,1023369,1,2,1,1,1253889535,1253889775,240,30,152.163.141.8,US,0,00,
1,1026987,1026987,1,2,6,72,1253889535,1253889775,240,30,152.163.141.8,US,0,00,

I am not quite comfortable with sed, awk or perl. Your help is really appreciated.

Thanks,
Toms

Backup your data first:

sed 's [^,]*$  ' infile > _tmp_ && mv -- _tmp_ infile

Some sed implementations support in-place editing with the -i switch,
in that case you don't need to redirection and the mv command.

---------- Post updated at 12:15 PM ---------- Previous update was at 12:13 PM ----------

To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags

```text
 and 
```

by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums

$sed -i.BAK 's/,\-g [0-9]\+//g' inputfile

a very easy way is to set the last field to null

nawk -F"," '{ $NF="" } 1 ' OFS=","   input_file

Best Regards

Or if you have GNU awk:

gawk -F, NF-- OFS=, infile