Using sed to...

Hello everyone,

I'm developing a script in which I would like for the following functions to be performed in sed:
 - Deletes lines that begin with the character '#'
 - Every comma is followed by exactly one space.
 - Every period is followed by exactly two spaces.

I'm getting frusterated using this, any help is greatly appreciated :)
justinmaurerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

wesly_chenCommented:
Hi,

   The first is easy
sed '/^#/d' filename

   The second and the third is difficult because "space".  I haven't figure it out

Wesly
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TintinCommented:
To delete the other lines, use

sed '/, [^ ]/D'

sed '/\.  [^ ]/D'
0
ishandoCommented:
This should do all three tasks:

 sed -e 's/,[ ]*/, /g' -e 's/\.[ ]*/.  /g' -e '/^#.*/ D' test.txt
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

TintinCommented:
Ahh, I misinterpretted the original question.  The above can be simplified to:

sed -e 's/, */, /g' -e 's/\. */.  /g' -e '/^#/D' test.txt
0
gisellla_igrCommented:
try this
sed -e'/^#/d' -e 's/\.  [^ ]//g' -e 's/\.  $//g' -e 's/, [^ ]//g' -e 's/, $//g'

it deletes de lines thaat begin with '#' and delete the characters ', ' and '.  '
0
TintinCommented:
gisella_igr.

You have also misinterpretted the original question.
0
ahoffmannCommented:
500 points for a simple homework question?
either read
   man sed
or please post what you have done so far, then we can help
0
gisellla_igrCommented:
Tintin, why you say that I misinterpretted the original question?
0
TintinCommented:
The original question (perhaps not worded so clearly) was to make sure each line that has a comma is followed by one space and that each line with a . is followed by two spaces.

For example:

This line,   is short. But isn't formatted correctly.

To become

This line, is short.  But isn't formatted correctly.
0
ozoCommented:
I don't see two spaces after that last .  
0
gisellla_igrCommented:
ok, I understand.
Thanks Tintin.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.