Unix pipelines || filter || questions || help || needed

There will be B’day celebration from the friends file, find how many B’day parties will be
held. If two of the friends have the B’date on the same day, then we will be having one
party on that day.

#unix

Hello,

Welcome to the forum. However, I have to say that I honestly have no idea what question, if any, you are asking here. The subject implies that you are wanting to know more about the use of UNIX pipes, but the actual message body of your post, I'm afraid, does not seem to make any kind of sense to me.

Can you please have another try at describing the problem you are trying to solve ? If you can also show us the work that you have attempted so far to solve it, and provide an explanation of the issues you've run in to whilst trying to do so, that would be very helpful. Lastly, if you can also include information about the environment you're attempting to solve this problem on (e.g. operating system and version, hardware architecture, the shell or language you're using, etc), then we may have a chance at assisting you further here.

1 Like

There will be B’day celebration from the friends file, find how many B’day parties will be
held. If two of the friends have the B’date on the same day, then we will be having one
party on that day.

actually sir this is the question in unix and i have to solve that using pipelines or filters concepts written in my document. So kindly help with the solution because many question after this related to this question answer only.

Thanks

Hello,

Is this question related to academic work, or coursework - from a UNIX LabBook, say ? Please consider your answer carefully, as it would be far better to be up-front about this than not. We will still be able to help you even if this is related to coursework, though our assistance would take the form of helping you to understand the concepts you'd need to master in order to complete your assignment.

2 Likes

Thanks. When I can able to get the answer ?

Hello,

When you answer the questions that have been put to you, I imagine. Is this related to academic coursework ? If it is, you need to clearly state that.

2 Likes

yes its an assignment. can you please help me in that question , i tried but not able to solve

Hello,

Great, thank you for confirming that. Are you able to show us what you've attempted ? No matter how little it is or what the end result was, seeing what you've tried so far will help us know what you're struggling with precisely, and enable us to give you the best answer possible to help you progress in your work.

2 Likes
echo -n "Enter the birthdate (mm-dd-yyyy): "
read bdate

bmonth=${bdate:0:2}
bday=${bdate:3:2}
byear=${bdate:6:4}

well actually I was trying with these shell commands only bash scripts but its not the answer because they are asking to solve this by using the pipelines or filter commands only using linux / ubuntu machine / cgwin is also good. Can you please help in this.

Hello,

OK, thank you. The original problem as stated is not at all clear. I don't think that's your fault however, as I've found the "UNIX for Users - LabBook" document that it seems to come from, and it's just as un-clear there as it is in your posting here. Without knowing more about the sample data, what's in this "friends file", how it's formatted, and...well, anything at all really...about what we're actually working with, it's not possible to give a specific answer.

But, if you're wanting to know more about pipes, I can certainly help you with that. The basic idea with pipes is that they are used to pass the output of one command on to another command as its input.

Consider the following sample data:

$ cat fruits
apple
banana
orange
banana
strawberry
strawberry
raspberry
apple
banana
kumquat
banana
$

Here we have a list of fruits, in no particular order. Let's say we've been asked to find out how many times each of these fruits appear in the file. We can do this using pipes to join multiple commands together, to step-by-step build a working solution out of the basic commands that UNIX-style operating systems provide to us.

The first step is to sort the file. We do this with the sort command. I should note there are far more efficient solutions to this problem than what I'm about to describe, but in order to demonstrate the use of pipes as fully as possible to you, we'll do it this way:

$ cat fruits | sort
apple
apple
banana
banana
banana
banana
kumquat
orange
raspberry
strawberry
strawberry
$

So, we used cat to view the contents of our file, and then used a pipe (represented by the vertical bar | symbol) to pass that output on to the sort command as its input. It then sorted the input it was given, and wrote it in its newly-sorted form to its output.

Now, let's count how many times in a row each of these fruits are listed:

$ cat fruits | sort | uniq -c
      2 apple
      4 banana
      1 kumquat
      1 orange
      1 raspberry
      2 strawberry
$

Now we've added another stage to our pipeline, by piping the output of sort into the uniq command. The uniq command on its own would remove all duplicates in its input. However, the use of the -c flag tells it to produce a count of the number of times each unique line appears.

Lastly, let's say we want to sort this list, from lowest to highest. We could add another pipe like this:

$ cat fruits | sort | uniq -c | sort -n
      1 kumquat
      1 orange
      1 raspberry
      2 apple
      2 strawberry
      4 banana
$

This last command in the pipeline is another use of sort. The -n flag tells it we want to do a numerical sort rather than an alphabetical one, thus giving us the number of times each fruit appears in the file, from lowest to highest.

I hope this has helped to demonstrate pipes, and gives you an understanding of how they may be used to solve your problem. If you have any further questions about them, please let us know and we can take things from there.

2 Likes

yea, thanks for the concept and in the question its mentioned that i need to create the friends file if needed .

i think i need to create the file by usning cat > friends then enter and ctrl+d i need to put some friends birthday related information so that i will able to match with the expected answer. anyway still help is needed. please try to give me particular amswer or solution for this question. I am added some more with this so it will clear for you. please check again.

There will be B’day celebration from the friends file, find how many B’day parties will be
held. If two of the friends have the B’date on the same day, then we will be having one
party on that day.

Display the lines starting with Ma, in the file friends.
Display the lines starting with Ma, ending with i or ending with id, in the file friends.

some condition related question with pipeline and filter command in unix/linux

Thanks

Hello,

We can help you understand concepts that you need to solve the problem, and answer questions about why specific parts of your attempted solution are not working. What we can not and will not do, however, is write your answer for you. That would be directly against the rules of this forum.

At the end of the day, this is your coursework, and the answer has to come from your own efforts. The submission of code that others have written for you would be dis-honest, and ultimately unhelpful, as the best way to learn something is by making a full and honest attempt at doing it yourself.

As I say, we are more than happy to explain anything you are wanting to know more about, and to assist you with any parts of your own work that you are struggling to understand or to get working. But that is as far as our help can go.

3 Likes

Ok no problem. I will ask you in case I have any problem in the unix concepts. Yes sir you are right. Thanks for the guidance and help. I think I got some idea . Will check and try again. Thanks for your effort and time.

Thanks

1 Like

how can i show any content of a file pagewise by the single command

tried with ls -lt | more -d but not showing the page wise
what should be the command ?

ls -al | more -d

but i created a file and i need to see the contents of that file only but pagewise.

Hello,

The ls command is used for viewing information about a file or directory, such as its filename, permissions, size, date and time of its last modification, and so on. The cat command is used for viewing the contents of a file.

Compare:

$ ls
fruits
$ ls -l fruits
-rw-rw-r-- 1 unixforum unixforum 87 May 14 22:13 fruits
$

with:

$ cat fruits
apple
banana
orange
banana
strawberry
strawberry
raspberry
apple
banana
kumquat
banana
$

However, you can directly use pagers such as more and less on a file to view them - just type more <filename> or less <filename>.

Hope this helps !

2 Likes

I tried with more then filename.txt but its not showing me the pages appropiatly. Is there any other way ? more is working like cat only in my case not showing the pages while using this command

Hi,

You'll only see multiple pages of a file when using more if there are actually multiple pages to see.

The purpose of pagers like more is to show you just one screenful at a time of data from a file that's got more lines in it that your current screen can display in one go. So for a typical terminal, unless your file is more than 25 or 50 lines long, the effect of cat and more will indeed be identical.

The use of a pager doesn't change the format of a file at all, or modify its contents in any way - it just means that you can view one screenful of data from a file at a time, and then you press the spacebar to see the next screenful. And when you're done, you press q to quit and return to your shell.

2 Likes

How to display the lines starting with some word from any file ??

sort | [ ]

cat | [ya]* trying with this can you help.
without global regular (grep) command
??

Hello

That is exactly what the grep command is for - displaying the parts of the input that match a particular pattern, or a given regular expression. You can't use cat on its own to display only the bits of a file that you want. Is there a particular reason you don't want to use grep ?

1 Like

No but i was thinking is there any other way to solve it in case there are any option not present for using grep. ok another problem is i want to show the contents of any file in upper case letter can you please tell me that command with explaination. Do I need to use the awk command here or any way to solve with the grep ??