473,388 Members | 1,198 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

help needed with C grep program. About pipes and ls in shell

Hello,

I need to program grep (like the one UNIX has but more simple)
For example if the programs name(the grep I will write) is p3 then if
I write in shell
p3 story.txt word

The output should be all lines where the word "word" appears.

The problem is that I am suppose to use this command in shell as well
ls | p3 word

The output should be the lines that the word "word" appears in with in
all files of the directory.

My question is what can I do with that? I mean ls is not my command
its a shell command. What kind of paramters do I get in order to
understand that I need all the files and how do I find all the files
in the directory. The first case isn't that clear either.

Any tutorial or something (like a *.h) files that can help?

Thanks
Nov 14 '05 #1
3 2195

"E.U." <el******@gmail.com> wrote in message
news:c2**************************@posting.google.c om...
Hello,

I need to program grep (like the one UNIX has but more simple)
<snip>
My question is what can I do with that?
Lots. Grep is a very usefull utility.
I mean ls is not my command its a shell command.


Ah... And the question is "How do I get at the command-line arguments" ?

Try this. It may give you a hint or two...

#include <stdlib.h>
#include <stdio.h>

int main(int argc, char* argv[], char* envp[])
{
printf("number of arguments = %d\n", argc);

for(i=0; i<argc, i++)
{
printf("argv[ %d] = %s\n", i, argv[i]);
}

return EXIT_SUCCESS;
}

when compiled (into, for instance, foobar) type

"foobar this is an argument, too" and hit [RETURN].
Nov 14 '05 #2
E.U. <el******@gmail.com> spoke thus:
The output should be all lines where the word "word" appears.
strstr() will be useful, I suspect.
The problem is that I am suppose to use this command in shell as well
ls | p3 word
As well as what?
My question is what can I do with that? I mean ls is not my command
its a shell command. What kind of paramters do I get in order to
understand that I need all the files and how do I find all the files
in the directory. The first case isn't that clear either.


(caveats may apply)

<ot>The command you listed pipes the output of ls to the standard
input of p3. You can simply read lines from standard input and pass
them to fopen() and proceed from there.</ot>

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Nov 14 '05 #3
"E.U." wrote:

I need to program grep (like the one UNIX has but more simple)
For example if the programs name(the grep I will write) is p3
then if I write in shell
p3 story.txt word

The output should be all lines where the word "word" appears.

The problem is that I am suppose to use this command in shell
as well ls | p3 word

The output should be the lines that the word "word" appears in
with in all files of the directory.


So write it as a filter. You run it with:

p3 word <story.txt

My just released id2id-20 is an example of this.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!

Nov 14 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Sims | last post by:
Hi, Given a string $txt and an array of strings $txt_array what would be the best/fastest way to search in _insensitive_ case if $txt is in $text_array and, if it is, where is it? Because I...
6
by: Jack Smith | last post by:
Help needed on this question. Any help is appreciated. Thanks in advance. Given a binary string (i.e. a finite sequence of 0's and 1's) we choose any two digit substring 01 and replace it by a...
1
by: worzel | last post by:
Hi All, I am looking for a reg ex that will match email addresses withing <a href=mailto blah > links. Actually, I already crafted my own, but with a slight problem: <a...
2
by: Eric Chase | last post by:
Can someone please help with a program that I have. I would like to find out what it would take to run it, or how to run it. There is only one file with the extention (.c) and the rest of the...
3
by: coopst1 | last post by:
below is my almost completed code. I need help trying to figure out how to display to a textarea all the data I have in phpMyAdmin (database). I have two methods near the bottom called itemResults()...
1
by: sxi12345 | last post by:
I need some help with a program im trying to code. The form consists of a listbox and three texts boxes and a button. Two texts boxes will be to enter a start value and an end value. The other...
0
by: mich | last post by:
Hello , i need help with a program that uploads files to a ftp server so far i got everything i only need to know how i declare it this is what i got so far Dim success As Boolean ...
7
by: rohitsripathi | last post by:
i need help writing this program... i am in college and i do not have time do this right now as i need to study for another test....but this is due tonight...i will pay $5 if you accept to do it and...
1
by: Joel Fireman | last post by:
Help Needed: Upgrade Fedora 4 / Apache 2 to PHP 5.2.x from 5.0.4 I've been testing Joomla as a content manager for the County offices, and it looks pretty good. Unfortunately, I decided to...
0
by: Shane Fitz | last post by:
I can't seem to get my program to setup the hashed dictionary correctly. It seems to keep the last entry in, and references every key to that entry. dictsetup(h:HASHED_DICTIONARY , STRING];...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.