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

Posted on 2014-08-21
Last Modified: 2014-08-23
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.
Question by:digs developer
    LVL 2

    Expert Comment

    by:Priya Sudharsan
    Try this.

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

    Open in new window

    LVL 84

    Accepted Solution

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Suggested Solutions

    This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
    FreeBSD on EC2 FreeBSD ( is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now