Computing.Net > Forums > Unix > replace last comma of first line

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

replace last comma of first line

Reply to Message Icon

Original Message
Name: ahmedwaseem2000
Date: August 25, 2005 at 04:20:50 Pacific
Subject: replace last comma of first line
OS: HPUX
CPU/Ram: 256
Comment:

hi , i have a comma seperated file with 1 line which is terminating with a comma in last now i wanted to remove the last comma. can any one tell me how to do that please.

Many Thank,
waseem


Report Offensive Message For Removal


Response Number 1
Name: anilcgowda
Date: August 25, 2005 at 12:42:07 Pacific
Reply:

Waseem,

Suppose your file is having 10 fields per record. Means your record would look like:
a,b,c,d,e,f,g,h,i,j

According to you, there is a comma after j. So, the following code will remove the 10th occurance of "," in each line.

sed 's/|//10' <infile

Best Wishes,
Anil


Report Offensive Follow Up For Removal

Response Number 2
Name: anilcgowda
Date: August 25, 2005 at 12:43:31 Pacific
Reply:

one correction in above code:

sed 's/,//10' <infile


Report Offensive Follow Up For Removal







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home



Results for: replace last comma of first line

Finding Word count of first line
    Summary: Hi, I want to count the number of words in the first line of a textfile and check whether it is equal to 21. So I am doing like if [ `head -1 file.txt | w...
www.computing.net/answers/unix/finding-word-count-of-first-line/8219.html

Replace last character if comma
    Summary: Hi all, I have a setting file which I create on the fly, but in certain cases in added a comma to the end of the line. I need to remove this and replace with nothing. sed '$s/,$//' filename.dat Doesn'...
www.computing.net/answers/unix/replace-last-character-if-comma/5349.html

To remove last occurance of character
    Summary: Hi Jerry, I fully agree on the usage of sed Anyway be aware of the following: your file containes two lines e.g.: david, jerry hans,klaus, The out put of your script would be: david hans,klaus Where ...
www.computing.net/answers/unix/to-remove-last-occurance-of-character/3646.html








Which MP3 player do you have?

iPod/iPhone
Zune
Something Else
None


View Results

Poll Finishes Today.
Discuss in The Lounge
Poll History






Data Recovery Software