Hi. I am new in shell programming. I have this problem which I want to teach myself. Please head me in the right direction:
"Your program should read the output of wc as standard input. In another words, the program is to behave as if it were part of the pipeline. Typical execution would be
wc demofile.txt | your_program -[b | w | l]
Example 1:
$ wc demofile.txt | ./program -b
1) The number of files : 1
2) The largest file in byte : demofile.txt (7148 bytes)
3) The smallest file in byte : demofile.txt (7148 bytes) 4) The total number of bytes : 7148 bytes
How can I do this...I am complete noob in shell programming...
To start how I can I read the text file as string in to c++ code? What should be the var? what is |
then, once you understand how piping basically works, you just need to read from stdin to get the output, and your program will be able to work with what you need.
ashari@ashari-VirtualBox:~/Desktop/CPP/tests$ wc salam.txt | ./pipe b
1
ashari@ashari-VirtualBox:~/Desktop/CPP/tests$ wc salam.txt | ./pipe b w
1
1
ashari@ashari-VirtualBox:~/Desktop/CPP/tests$ wc salam.txt | ./pipe b w l
1
1
6
ashari@ashari-VirtualBox:~/Desktop/CPP/tests$ wc salam.txt | ./pipe b w l k
1
1
6
invalid command
ashari@ashari-VirtualBox:~/Desktop/CPP/tests$
Please tell me how as I increase command line argument for the pipe program output also comes correctly?? Also how can I output the file name? I tried adding get line, but it does not print out filename in cmd line
The 'wc' with one filename prints out one line of output that contains: number number number filename.
The 'wc' with more than one filename prints out one line for each file and then a total line.
Do man wc and read carefully. Then you should know what your input data should contain.
Your program should read one or more lines from std::cin. Your current program reads at most one integer.
I do interpret the synopsis of your program as the program expecting at most one command line argument. One word that should be "-b", "-w" or "-l".
You have not told whether your homework assignment instructions describe what those arguments mean. It is surprising, if they don't.