473,395 Members | 1,541 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,395 software developers and data experts.

delete all the entries that contain "some string" from a file

Dear all,

I have a text file call access.log and it contains about 5030 lines.
Some lines contain some keyword, e.g. "ricky ng".
How can I delete all the entries that contain "ricky ng" line and
write to a new file call access.trace.log.
I know we can use strstr() function.
But, I don't know how to use strstr() function.
Pls help me.

Thanks!
Nov 13 '05 #1
2 5326

"Rick Ng Chi Wah" <ng*******@netscape.net> wrote in message

I have a text file call access.log and it contains about 5030 lines.
Some lines contain some keyword, e.g. "ricky ng".
How can I delete all the entries that contain "ricky ng" line and
write to a new file call access.trace.log.
I know we can use strstr() function.
But, I don't know how to use strstr() function.

Read in each line using fgets().

The call strstr() on the line you have just read to see if it contains your
keyword.
If the line contains the keyword, send it to the log.
If the line doesn't, use fputs() to write it to a new file.

Repeat until you come to the last line of the file.

Swap filenames so that the new file replaces the old.
Nov 13 '05 #2
Rick Ng Chi Wah wrote:

Dear all,

I have a text file call access.log and it contains about 5030 lines.
Some lines contain some keyword, e.g. "ricky ng".
How can I delete all the entries that contain "ricky ng" line and
write to a new file call access.trace.log.
I know we can use strstr() function.
But, I don't know how to use strstr() function.
Pls help me.


If this is all you're doing then don't bother writing a program, just get on
UNIX (or Linux or download Cygwin) and run:

grep -v "ricky ng" access.log > access.trace.log

Regards,

Ed.
Nov 13 '05 #3

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

Similar topics

0
by: BW | last post by:
Please ignore the rest of the code, except for the highlighted part (or the line 'ent1=Entry(topf, width=25)' to line 'ent1.insert(INSERT, wrong, if you cannot see the color). You can copy this into...
2
by: RickL | last post by:
I have an ASP application that uploads a specified file to the server. To retrieve the file, I simply assign the filepath and file to a hyperlink on the page. When you click "Save Target As" for...
1
by: Kashish | last post by:
Is file<<"Some string"<<endl is an atomic operation. where file is an ofstream object. If we output a string in ofstream and we provide endl after that,Can we make sure the whole string will be...
2
by: srktnc | last post by:
When I run the program, I get a Debug Error saying "This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more...
5
by: ad | last post by:
I want to delete some text which begin with <!DOCTYPE and end with > in a file. How can I do it?
1
by: Marc Bishop | last post by:
can anyone help me with this? Code Snippet: Dim ArrCart As New ArrayList() if NOT Session("sesCart") = "" then ArrCart = Session("sesCart") Error: System.InvalidCastException: Operator is...
9
by: Fei Liu | last post by:
In Accellerated C++, the author recommends that in a header file one should not declare using std::string, using std::vector etc instead one should directly specify the namespace specifier in...
5
by: i.c.code | last post by:
maybe like: #include "boost/function.hpp" template <typename T> class Do_When_Return { private: Do_When_Return(const Do_When_Return&); Do_When_Return();
6
by: Warly girl | last post by:
Hi i want your help again in c++ !! i want a function change the "int" to "string" because in my project "Registration system" in task "b" i must write a course class which contains number of...
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:
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.