Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Using sed to...

Posted on 2004-11-17
11
Medium Priority
?
548 Views
Last Modified: 2013-12-26
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 :)
0
Comment
Question by:justinmaurer
11 Comments
 
LVL 38

Accepted Solution

by:
wesly_chen earned 400 total points
ID: 12609685
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
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 800 total points
ID: 12609848
To delete the other lines, use

sed '/, [^ ]/D'

sed '/\.  [^ ]/D'
0
 
LVL 15

Assisted Solution

by:ishando
ishando earned 800 total points
ID: 12610193
This should do all three tasks:

 sed -e 's/,[ ]*/, /g' -e 's/\.[ ]*/.  /g' -e '/^#.*/ D' test.txt
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 48

Expert Comment

by:Tintin
ID: 12610328
Ahh, I misinterpretted the original question.  The above can be simplified to:

sed -e 's/, */, /g' -e 's/\. */.  /g' -e '/^#/D' test.txt
0
 
LVL 1

Expert Comment

by:gisellla_igr
ID: 12616470
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
 
LVL 48

Expert Comment

by:Tintin
ID: 12620137
gisella_igr.

You have also misinterpretted the original question.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 12626367
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
 
LVL 1

Expert Comment

by:gisellla_igr
ID: 12629248
Tintin, why you say that I misinterpretted the original question?
0
 
LVL 48

Expert Comment

by:Tintin
ID: 12631789
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
 
LVL 85

Expert Comment

by:ozo
ID: 12636611
I don't see two spaces after that last .  
0
 
LVL 1

Expert Comment

by:gisellla_igr
ID: 12650443
ok, I understand.
Thanks Tintin.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question