LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Question about sed command (https://www.linuxquestions.org/questions/linux-software-2/question-about-sed-command-915500/)

rbalaa 11-25-2011 09:29 AM

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.

sycamorex 11-25-2011 09:35 AM

Yes, you certainly can.
A good tutorial will be http://www.grymoire.com/Unix/Sed.html

rbalaa 11-25-2011 09:38 AM

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.

sycamorex 11-25-2011 09:42 AM

Slightly cryptic hint: Just replace , with something and think globally:)

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

David the H. 11-25-2011 09:54 AM

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.

rbalaa 11-25-2011 09:58 AM

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)

rbalaa 11-25-2011 09:59 AM

Quote:

Originally Posted by sycamorex (Post 4533716)
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

sycamorex 11-25-2011 10:01 AM

Quote:

Originally Posted by rbalaa (Post 4533728)
Something like this ?

s/,//g

Should do:)

David the H. 11-25-2011 10:03 AM

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. ;)

rbalaa 11-25-2011 10:04 AM

Quote:

Originally Posted by sycamorex (Post 4533730)
Should do:)

excellent, thank you that worked ...

rbalaa 11-25-2011 10:05 AM

Quote:

Originally Posted by David the H. (Post 4533733)
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.

sycamorex 11-25-2011 10:07 AM

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


All times are GMT -5. The time now is 08:06 AM.