Skip to content
Advertisement

How can I check (and delete) if the last line (that contains the last occurence of a string) has a comma as last character?

I’ve been looking all over the internet but had no result.

I’m trying to build a package generator (in shell/bash) and that respective package contains (one or more) json files. When browsing through a json file, if the user wants to delete one of the steps I must first take into consideration what if the step he wants to delete is the last. If so, the previous of the last step will contain a comma, but the json format does not permit that.

JavaScript

Example, If I delete ‘”steps/Step2/02_park_the_car.json”‘, then ‘”steps/Step2/01_drive_the_car.json”,’ will be the last step, but the comma will then cause an error.

Thank you in advance everyone.

Advertisement

Answer

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement