Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 297
  • Last Modified:

Unix shell script,Please help on script for removing comma ?

I want to remove last comma from file Temp_B_ID_Comm.txt
It works proper but when file contains 1 record then in that case i want to remove comma(,).

sed "s/$/,/g"  Temp_B_ID.txt > Temp_B_ID_Comm.txt
sed -e '${s/$/ );\nGO/}' Temp_B_ID_Comm.txt > ABC_Missing_B_ID.txt
cat ABC_B.sql ABC_Missing_B_ID.txt > ABC_B_exec.sql

Please help.
digs developer
digs developer
1 Solution
Priya SudharsanProgrammer AnalystCommented:
Try this.

$ sed -i '$s/,$//' file.txt

Open in new window

sed '$!s/$/,/'  Temp_B_ID.txt > Temp_B_ID_Comm.txt

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now