LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-25-2011, 10:29 AM   #1
rbalaa
Member
 
Registered: Mar 2010
Posts: 61

Rep: Reputation: 0
Question about sed command


Hello,

Can I use sed to edit a txt file so that i removes all commas and combines the characters together ?

ie:

Before: 111,111,111
After: 111111111

Thanks for any help in advance.
 
Old 11-25-2011, 10:35 AM   #2
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233
Yes, you certainly can.
A good tutorial will be http://www.grymoire.com/Unix/Sed.html
 
Old 11-25-2011, 10:38 AM   #3
rbalaa
Member
 
Registered: Mar 2010
Posts: 61

Original Poster
Rep: Reputation: 0
Thanks syc. I was actually looking at that page. I'll try to find it. Was just wondering for some ideas/tips from the forum. Thanks.
 
Old 11-25-2011, 10:42 AM   #4
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233
Slightly cryptic hint: Just replace , with something and think globally

edit: Slightly less cryptic hint: Just replace , with nothing and think globally.

Last edited by sycamorex; 11-25-2011 at 10:54 AM.
 
Old 11-25-2011, 10:54 AM   #5
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,845

Rep: Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006
Simple character replacement or deletion can also be done with tr.

And if the string is already stored in a shell variable, then there are a load of string manipulation techniques available to you.
 
Old 11-25-2011, 10:58 AM   #6
rbalaa
Member
 
Registered: Mar 2010
Posts: 61

Original Poster
Rep: Reputation: 0
I must use sed becuase tr is not in my mks toolset. i'm trying to do this in a dos batch file. i'm just not familiar with sed at all (not since school, a long time ago, lol)
 
Old 11-25-2011, 10:59 AM   #7
rbalaa
Member
 
Registered: Mar 2010
Posts: 61

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by sycamorex View Post
Slightly cryptic hint: Just replace , with something and think globally

edit: Slightly less cryptic hint: Just replace , with nothing and think globally.

Something like this ?

s/,//g
 
Old 11-25-2011, 11:01 AM   #8
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233
Quote:
Originally Posted by rbalaa View Post
Something like this ?

s/,//g
Should do
 
Old 11-25-2011, 11:03 AM   #9
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,845

Rep: Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006
No problem then. But it might help if you mention platform limitations like that when you post. It can have a big effect on whether you get useful answers.

As for your posted command, try it and see.
 
Old 11-25-2011, 11:04 AM   #10
rbalaa
Member
 
Registered: Mar 2010
Posts: 61

Original Poster
Rep: Reputation: 0
Cool

Quote:
Originally Posted by sycamorex View Post
Should do
excellent, thank you that worked ...
 
Old 11-25-2011, 11:05 AM   #11
rbalaa
Member
 
Registered: Mar 2010
Posts: 61

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by David the H. View Post
No problem then. But it might help if you mention platform limitations like that when you post. It can have a big effect on whether you get useful answers.

As for your posted command, try it and see.
Will do, thx David.
 
Old 11-25-2011, 11:07 AM   #12
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233
Glad to hear it. You might want to mark this thread as solved (in the thread tools)
 
  


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] Problem - question for command inside sed. logar0 Linux - Newbie 10 10-25-2010 12:41 PM
sed command question mokku Linux - Newbie 2 03-05-2008 12:30 PM
sed command Kalyani1 Linux - Software 28 12-07-2005 12:48 PM
sed command rharris72 Programming 6 11-20-2005 09:26 PM
question about using sed command feetyouwell Linux - Software 4 12-13-2004 09:47 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:14 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