Purchase Linux CDs / DVDs / Flash Drives at OSDisc.com

Welcome to Our Community

While Linux.org has been around for a while, we recently changed management and had to purge most of the content (including users). If you signed up before April 23rd, 2017 please sign up again. Thanks!

  1. More ways to get the info! - we shoot all of our new original content out as well as random messages on Twitter and our newsletter!. Twitter | Newsletter
    Dismiss Notice

New to the forum New to Linux

Discussion in 'Command Line' started by Raymond2688, Feb 10, 2019.

  1. Raymond2688

    Raymond2688 New Member

    Joined:
    Feb 10, 2019
    Messages:
    4
    Likes Received:
    2
    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
    Step
    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'


    (Log in to hide this advertisement)



    upload_2019-2-10_7-40-25.png
     

    Attached Files:

  2. Condobloke

    Condobloke Well-Known Member

    Joined:
    Apr 30, 2017
    Messages:
    713
    Likes Received:
    729
    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.
     
  3. Raymond2688

    Raymond2688 New Member

    Joined:
    Feb 10, 2019
    Messages:
    4
    Likes Received:
    2
    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.
     
  4. wizardfromoz

    wizardfromoz Super Moderator
    Staff Member Gold Supporter

    Joined:
    Apr 30, 2017
    Messages:
    2,785
    Likes Received:
    2,249
    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
    wizardfromoz
     
  5. Raymond2688

    Raymond2688 New Member

    Joined:
    Feb 10, 2019
    Messages:
    4
    Likes Received:
    2
  6. JasKinasis

    JasKinasis Well-Known Member

    Joined:
    Apr 25, 2017
    Messages:
    367
    Likes Received:
    687
    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:
    Code:
    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:
    Code:
    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:
    Code:
    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:
    Code:
    sed -- 's/,//g; s/://g; s/;//g; s/\.//g; /^[[:space:]]*$/d' usdeclar.txt > sed_edits.txt
    
     
    #6 JasKinasis, Feb 11, 2019
    Last edited: Feb 11, 2019
    wizardfromoz, Rob and Condobloke like this.
  7. Raymond2688

    Raymond2688 New Member

    Joined:
    Feb 10, 2019
    Messages:
    4
    Likes Received:
    2
    @JasKinasis thank you so much for taking the time to help me with this. It worked perfect, and with your explanation know what I did wrong. You guys are great.....this is a new week I'm sure ill be back.
     
    wizardfromoz and Condobloke like this.
  8. JasKinasis

    JasKinasis Well-Known Member

    Joined:
    Apr 25, 2017
    Messages:
    367
    Likes Received:
    687
    No worries - always glad to help!
     
    Condobloke likes this.
  9. wizardfromoz

    wizardfromoz Super Moderator
    Staff Member Gold Supporter

    Joined:
    Apr 30, 2017
    Messages:
    2,785
    Likes Received:
    2,249
    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


    [​IMG]



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

    https://www.linux.org/forums/member-introductions.141/

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

    Cheers

    Wizard
     
    JasKinasis likes this.

Share This Page