LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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, 02: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, 02:46 PM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
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, 02: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, 03:04 PM   #4
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
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 08:53 AM
[SOLVED] How to remove line breaks from lines ending with a comma jasonws Linux - General 1 11-10-2010 12:03 PM
How to delete Comma in a comma separated file with double quotes as quote character pklcnu Linux - Newbie 2 03-24-2009 05:50 PM
using sed to remove line in a comma-delimited file seefor Programming 4 03-10-2009 03:35 PM
Need a script to remove last comma in a file jgombos Programming 15 01-14-2008 01:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:04 AM.

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
Open Source Consulting | Domain Registration