LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-29-2012, 03:42 PM   #1
betsy1181
LQ Newbie
 
Registered: Feb 2012
Posts: 6

Rep: Reputation: Disabled
Remove the first comma in a TXT fil


I would like to remove the first comma in a text file. My file is comma delimited data so i want to be sure that i only strip the first comma and no other ones. Can you please help me?
 
Old 02-29-2012, 03:46 PM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
To remove the first comma in every line within the file (and not simply the first comma in the file as a whole):

Code:
sed -i.backup 's@,@@' filename
This will modify the file directly, but store an unmodified, backup copy of the file as filename.backup.
 
Old 02-29-2012, 03:57 PM   #3
betsy1181
LQ Newbie
 
Registered: Feb 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
Thank you for your help, but I was not clear. I would like to be able to remove ONLY the first comma in the file.
 
Old 02-29-2012, 04:04 PM   #4
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
If the first comma is on line 1:
Code:
sed -i.backup '1 s@,@@' filename
If the first comma is on another line, change the number as appropriate.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] bash/sed/awk to convert comma's not in quotes in a line with many comma's oly_r Programming 23 01-25-2012 09:53 AM
[SOLVED] How to remove line breaks from lines ending with a comma jasonws Linux - General 1 11-10-2010 01:03 PM
How to delete Comma in a comma separated file with double quotes as quote character pklcnu Linux - Newbie 2 03-24-2009 06:50 PM
using sed to remove line in a comma-delimited file seefor Programming 4 03-10-2009 04:35 PM
Need a script to remove last comma in a file jgombos Programming 15 01-14-2008 02:30 PM


All times are GMT -5. The time now is 04:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration