Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2007
    Posts
    16
    Rep Power
    0

    Pipe command questions..


    1. Write a pipe that Counts the number of files in a certain directory using wc command

    2.Write a pipe that Counts the number of files that have dot (.) in the their name (for example, memo2.sv

    3.Write a pipe that Creates a file named "number" that contains the number of users currently logged in . using pipe and I/O redirection

    4.Write a pipe that Sorting:
    a. Create a file called days that contain the days of the week, one per line.
    b. Use a pipe to display a sorted list of the days to the screen.
    c. Repeat b) but direct the output to a file called days_sort.

    5.Write a pipe that Prints out the login names (and only the login names) of the four users that most recently logged to your UNIX machine.
    i was told to use the last command to print out the last logins and grep to filter out irrelevant lines of the output
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2006
    Posts
    2,632
    Rep Power
    1811
    Is this, and your other post, course/class/home work by any chance?
    What have you tried thus far?
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2007
    Posts
    16
    Rep Power
    0
    a found a way to do my last post

    they are all solved using
    ls manipulation
    i read in my book


    but i dont know what to do in this cases
    the only thing i know about pipe
    is thant connects several commands
    but
    i realy dont know what commands compose these pipes
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2006
    Posts
    2,632
    Rep Power
    1811
    A few hints:

    Code:
    ls -1 | wc -l
    Code:
    ls -1 | grep -c "\."
    We are piping the output from the ls command into the input for another command.
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2007
    Posts
    16
    Rep Power
    0

    to wich question your hint addresses..


    can you wright a hint on each question plz
    because i am new at UNIX

    so i can learn more about this...
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2007
    Posts
    16
    Rep Power
    0

    how do i solve the rest


    3.Write a pipe that Creates a file named "number" that contains the number of users currently logged in . using pipe and I/O redirection

    4.Write a pipe that Sorting:
    a. Create a file called days that contain the days of the week, one per line.
    b. Use a pipe to display a sorted list of the days to the screen.
    c. Repeat b) but direct the output to a file called days_sort.

    5.Write a pipe that Prints out the login names (and only the login names) of the four users that most recently logged to your UNIX machine.
    i was told to use the last command to print out the last logins and grep to filter out irrelevant lines of the output
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2006
    Posts
    2,632
    Rep Power
    1811
    Look at each individual command (cross-reference them in man or info pages) to see what it does.
    command 1: ls -1
    command 2: wc -l
    ls is the basic list command, which lists directory entries. The -1 option says list them 1 line at a time (as opposed to in columsn across the screen).
    wc
    is the word count command which, with the -l option counts lines. See where are going with this? wc wants to read input lines to count and ls will be providing lines that can be counted. How do we get from one to the other? We use a pipe (the | character).
    Thus, with just this as an example we pipe the output of the ls -1 (one directory entry per line) into the wc command, telling wc to count the number of lines.

    What you need to do is to find the commands that do most or all of what you want and then pipe the output of that command into another command to process is it some way - for example to count lines, or to just look for specific strings (for which you'd use grep).
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2007
    Posts
    16
    Rep Power
    0

    i cant solve the last


    .Write a pipe that Prints out the login names (and only the login names) of the four users that most recently logged to your UNIX machine.
    i was told to use the last command to print out the last logins and grep to filter out irrelevant lines of the output

    ???
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2006
    Posts
    2,632
    Rep Power
    1811
    Yes, the last command will help in that. Have you run it to see what it will normally produce? Perhaps there is another program/utility that will just display the head of a file (and passing output via a pipe makes it the standard input 'file' for the other program?
    With grep (if you check the man/info pages) you will see a -v option: that could be handy.
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2007
    Posts
    16
    Rep Power
    0

    i got the first half what next


    last -4


    what next how do i finish this 5th question
    5. Prints out the login names (and only the login names) of the four users that most recently logged to your UNIX machine.
    i was told to use the last command to print out the last logins and grep to filter out irrelevant lines of the output
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2006
    Posts
    2,632
    Rep Power
    1811
    You are doing well - keep up the good work!
    Now, with that last one (pardon the pun!) we are going to need to be a little more tricky I think. The last command will list (as you will have seen) the logins of various users in date order, most recent first. But it will list the same user multiple times if they have logged in multiple times and you just want the last 4 users, not last 4 logins! It is possible (you will need to check) that using the -u (unique) option of sort on the user name part of the output may help here.
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2007
    Posts
    16
    Rep Power
    0

    i niticed my mistake but...


    i tried to execute the
    last -4 -u it itsnot working

    how do i execute this -u command the
    rest of the command is fishined
    i only need the -u part so it will
    show the last 4 users
    ??
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2006
    Posts
    2,632
    Rep Power
    1811
    The -u is a parameter to the sort command.
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  26. #14
  27. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2007
    Posts
    16
    Rep Power
    0

    the problem is much more complicated...


    each time i enter the console it regesters as a login
    even thow i didnt loged out of the system.

    so the problem is that after i opened the console box 4 times
    the command:
    last -4|cut -d" " -f1| uniq -u

    it only showed a single user.
    another problem is that if i change it to : last -50
    it showed the same user multiple times.

    how to i make a command that will show the last 4 users that logged in,
    and that they will show only 1 time???
  28. #15
  29. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2006
    Posts
    2,632
    Rep Power
    1811
    Do the last command ... send (all) the output to cut and get just the user, send THAT output on to uniq (to get unique values) then send that on to head to get the top 4 entries.
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo