Grep: Copy all lines from log file into new file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep: Copy all lines from log file into new file
# 1  
Old 03-13-2009
Grep: Copy all lines from log file into new file

Hello everyone. I have a log file that contains multiple domains:
I need to copy all of the lines that contain "www.thisdomain.com" from the log and output them into a new file. I've tried everything with little luck. Please help and thanks!
# 2  
Old 03-13-2009
Quote:
Originally Posted by aberli
Hello everyone. I have a log file that contains multiple domains:
I need to copy all of the lines that contain "www.thisdomain.com" from the log and output them into a new file. I've tried everything with little luck. Please help and thanks!
This is assuming it's an already static log file and you aren't "scraping" a file that's being written to at all times.

Code:
grep 'www\.thisdomain\.com' testing.txt >> tmp.txt

# 3  
Old 03-13-2009
Quote:
Originally Posted by cbo0485
This is assuming it's an already static log file and you aren't "scraping" a file that's being written to at all times.

Code:
grep 'www\.thisdomain\.com' testing.txt >> tmp.txt

I forgot to mention that the match has to be in the cs-host field as domains can show up in cs-referer as well. My solution below and thanks for your contribution:

grep -E "(.*) (.*) (.*) (.*) (www\.raileurope\.com)" filename.log > newfile.log

The cs-host column is the 5th column in the log file.
# 4  
Old 07-01-2009
Hi Aberli,

This is quite easy, lets say your file 'myfile.txt' contains some lines having --> www.thisdomain.com
and you need all the lines having www.thisdomain.com into a new file e.g. myfile_new.txt
Use the following command:

grep "www.thisdomain.com" myfile.txt >> myfile_new.txt

Regards,
Sumedha

Last edited by Sumedha Sobti; 07-05-2009 at 02:42 AM..
This User Gave Thanks to Sumedha Sobti For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copy lines from x to y to another file

OS : RHEL 7.2 Shell : bash I have a file which has lines like below I want to copy from 2nd line to the 6th line and copy(redirect) those lines to another file. $ cat patterns.txt hello world hello asia hello europe hello africa hello america hello antartica hello... (9 Replies)
Discussion started by: omega3
9 Replies

2. UNIX for Beginners Questions & Answers

How to copy only some lines from very big file?

Dear all, I have stuck with this problem for some days. I have a very big file, this file can not open by vi command. There are 200 loops in this file, in each loop will have one line like this: GWA quasiparticle energy with Z factor (eV) And I need 98 lines next after this line. Is... (6 Replies)
Discussion started by: phamnu
6 Replies

3. Shell Programming and Scripting

How to copy lines that starts with either 3 or 4 into new file?

Hi Guys, I have an awk script that would search the input file for line that starts with a number 3 and copies into a new text file. I want to extend this script to find the lines that either starts with 3 or a or b and copy all those lines into the new file. Here is what I have so far:... (1 Reply)
Discussion started by: Amith821
1 Replies

4. Shell Programming and Scripting

copy range of lines in a file based on keywords from another file

Hi Guys, I have the following problem. I have original file (org.txt) that looks like this module v_1(.....) //arbitrary number of text lines endmodule module v_2(....) //arbitrary number of text lines endmodule module v_3(...) //arbitrary number of text lines endmodule module... (6 Replies)
Discussion started by: kaaliakahn
6 Replies

5. Shell Programming and Scripting

Copy selective lines from text file

Hello, I have a text file which I need to check for presence of certain tags, and then copy a subsequent portion of text into another file. The tag matching canbe done with Grep but I do not know how to copy selective lines from one file to another. Is it possible do that? I checked up some... (8 Replies)
Discussion started by: ajayram
8 Replies

6. Shell Programming and Scripting

Help me! grep the log file without blank lines in column

Hi, I have log file like this: i want grep the log file without blank lines in column 4. So the file is become like this : What is the command? please help me. (1 Reply)
Discussion started by: justbow
1 Replies

7. Shell Programming and Scripting

Script to capture new lines in a file and copy it to new file

Hi All, I have a file that gives me new line/output every 5 minutes. I need to create a script that capture new line/output besides "IN CRON_STATUS", in this case the new output is "begin ------ cron_status.sh - -----------". I want this script to capture the line starting from "begin ------... (0 Replies)
Discussion started by: fara_aris
0 Replies

8. UNIX for Advanced & Expert Users

Copy lines from a log file based on timestamp

how to copy lines from a log file based on timestamp. INFO (RbrProcessFlifoEventSessionEJB.java:processFlight:274) - E_20080521_110754_967: rbrAciInfoObjects listing complete! INFO (RbrPnrProcessEventSessionEJB.java:processFlight:197) - Event Seq: 1647575217; Carrier: UA; Flt#: 0106; Origin:... (1 Reply)
Discussion started by: ranjiadmin
1 Replies

9. UNIX for Dummies Questions & Answers

copy lines from opne file to another

Hi all, I'm new to shell scripting. I want to copy the first N lines from a file to another file. Can someone please tell me how this can be done. Thanks Himi (2 Replies)
Discussion started by: HIMANI
2 Replies

10. Shell Programming and Scripting

Copy only the initial 10 lines from a file to another

Hi all, I'm new to shell scripting. I want to copy initial few lines(say first 10 lines) from a file to another file. There is no "head" command in our embedded system. sed & awk is there which I believe will do that, but I dont know how to. This is linux 2.6 (embedded) So please help me.... (5 Replies)
Discussion started by: jockey007
5 Replies
Login or Register to Ask a Question