• Important: We recently upgraded our forum software - please let us know if you run into any issues.

New to the forum New to Linux


New Member
Good morning everyone,
I am new to the forum and very new to Linux. I am currently taking an intro to Linux class, and I can't believe how hard this class is. I would never have thought I would be close to failing an intro class, but it is what it is. I came to this forum to see if I can get some help. I have been days on this one string I have to create. I am hoping that maybe you guys can help me out. Now, this is basic stuff, so I don't know why I can't get the hang of it, but here it goes. Below is the lab

Step 1 Use 'sed' to remove all punctuation from usdeclar.txt, which would be a comma, colon, semicolon and period
· Use 'sed' to remove all blank lines
· In other words, you will run 'sed '<expr>' usdeclar.txt' to remove a particular character. NOTE: There are ways to remove multiple characters, but do not do so.
· Review the slides or text book to find the correct subsitution <expr> to use.
· Or search the Internet to find the correct substitution <expr> to use for each particular character. For example, search for "how to remove …. using sed"
Step 1a – remove commas
· If you use the correct <expr>, the following should not return any results
sed '<expr>' usdeclar.txt | grep ','
Step 1b – remove colonssed

· If you use the correct <expr>, the following should not return any results
sed '<expr>' usdeclar.txt | grep ':'
Step 1c – remove semicolons

· If you use the correct <expr>, the following should not return any results
sed '<expr>' usdeclar.txt | grep ';'
Step 1e – remove periods sed '/^$/d' /tmp/data.txt > /tmp/output.txt

· If you use the correct <expr>, the following should not return any results
sed '<expr>' usdeclar.txt | grep '\.'NOTE: For grep, the period is escaped by the backward slash
Step 1f – remove blank lines -e '/^[[:space:]]*$/d'

· If you use the correct <expr>, the following should not show any blank lines
sed '<expr>' usdeclar.txt | head
1g – chain the commands
· Chain all of these 'sed' commands together using the pipe operation and rediect the output to sed_edits.txt
· The command chain should look like
sed '<expr>' usdeclar.txt | sed '<expr>' | sed '<expr>' | sed '<expr>' | sed '<expr>' > sed_edits.txt
NOTE: The 'sed' order be for removing commas, colons, semicolons, periods and blank line
This QUESTION is worth 20 points. Write your answer in the box.
What is the command chain you will run?

sed 's/,//g' usdeclar.txt | sed 's/://g' | sed 's/;//g' | sed 's/-//g' | sed 's/&//g' | sed 's/\.//g' | sed 's/ / /g' | sed '/^$/d' > sed_edits.txt (this is what I came up with) my word count is wrong
· Run 'clear'
· Run the command chain you entered in the box
· Run 'head sed_edits.txt'
· Run 'wc sed_edits.txt' to get the line, word and byte count of sed_edits.txt
· Run 'grep ',' sed_edits.txt | grep ':' | grep ';' | grep '\.'
NOTE: The 'grep' order should be for commas, colons, semicolons and periods
· Run 'date'




Well-Known Member
G'day Raymond, and Welcome to Linux.org

I have been using Linux Mint (cinnamon) for the past 4 years approx.....I can do everything necessary to run rings around most users.

But that "intro" material you have shown above leaves me cold.

To be fair, I dont actually need to know all that.....for me that would destroy all the fun I have using Linux as my daily/go to OS

Are your needs such that you need to have a serious grip on all of the above ??....I can only imagine the depths it will descend to when they move past the intro !!!

SO....not my forte at all....but there are others here who will likely be able to [email protected]JasKinasis is the first to spring to mind.


New Member
Thank you for your reply.
It is just a series of sed commands to remove punctuation, spaces, etc. from the declaration of independence. I'm on week 4 of a seven-week course and can't grasp the way this class is set up. I know these commands are the basic of the basic, but I don't know. Hopefully, someone will chime in. I am about to turn in what I got and be done with it. I have too many other classes to finish today and have spent days on this one lab.


Super Moderator
Staff member
Gold Supporter
G'day Raymond, another Aussie here and welcome :)

Totally agree with Brian, above. Whomever thinks that scripting with even minor complexity as being "Linux 101" is naive, at best :D

Jas, whom Brian has effectively "pinged" by using the @ with the userid, is one of a number here who may be able to assist.

@Rob , @nuna are a couple and I will think of more for you, albeit it is a little late perhaps now?

I will move this Thread to Command Line, and there you might get quicker assistance.

Cheers and good luck

Chris Turner


Well-Known Member
OK, so you are supposed to be stripping out comma, colon, semicolon and period characters from the text, plus any blank lines.
So you will need a total of five sed commands.

In your attempt:
sed 's/,//g' usdeclar.txt | sed 's/://g' | sed 's/;//g' | sed 's/-//g' | sed 's/&//g' | sed 's/\.//g' | sed 's/ / /g' | sed '/^$/d' > sed_edits.txt
You have 8 different calls to sed.
The first three are correct.
The fourth removes hyphens, which were not specified as a character for removal. So that might account for part of your word count/line count being off.
The fifth removes & characters, which were also not specified. So this may cause your word count to be off.
The sixth correctly removes periods/full-stops.

The seventh one is utterly pointless, this will replace all spaces with spaces. Which is the same as doing nothing!

The 8th pattern will remove empty lines, but it won't remove empty lines that have nothing but spaces and tabs in them.

From what I can see in what you posted - It looks like the pattern for removing blank lines has already been given to you in sed's extended regex format.
So the command to remove empty lines would be:
sed '/^[[:space:]]*$/d'
The above pattern will remove ANY line which is empty or contains only white-space characters like tabs or spaces.

So unless I'm missing something, what you need to do for this exercise is simply this:
sed 's/,//g' usdeclar.txt | sed 's/://g' | sed 's/;//g' | sed 's/\.//g' | sed '/^[[:space:]]*$/d' > sed_edits.txt
That should solve the problem for you!

And FYI - to do it in one single sed command, which would be more efficient - you'd do it like this:
sed -- 's/,//g; s/://g; s/;//g; s/\.//g; /^[[:space:]]*$/d' usdeclar.txt > sed_edits.txt
Last edited:


Super Moderator
Staff member
Gold Supporter
Jas is seriously mad, sick, wicked ... whatever, when he spins his voodoo, I just sit back like one of these guys and try to follow :D

Enjoy your Linux, Raymond, and if you get the time, swing over here


and say hi, tell us a little of the Raymond 2688 story, and meet a few more of The Gang.



Members online

No members online now.