remove comma from last line

后端 未结 3 1086
攒了一身酷
攒了一身酷 2020-12-19 04:26

How do I remove the comma from the last line of the file? Here is the file:

# cat ox_data_archive_r_20120727.json
{\"name\": \"secondary_ua\",\"type\":\"STRI         


        
3条回答
  •  清酒与你
    2020-12-19 04:54

    $ cat input.txt
    {"name": "secondary_ua","type":"STRING"},
    {"name": "request_ip","type":"STRING"},
    {"name": "cb","type":"STRING"},
    $ sed '$s/,$//' < input.txt
    {"name": "secondary_ua","type":"STRING"},
    {"name": "request_ip","type":"STRING"},
    {"name": "cb","type":"STRING"}
    

    From the documentation of GNU sed:

    $: This address matches the last line of the last file of input, or the last line of each file when the -i or -s options are specified.

提交回复
热议问题