Visit Our UNIX and Linux User Community


extracting part of a text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting extracting part of a text file
# 8  
Old 07-22-2009
hi guys
Thanks for your replies so far

This pattern doesnt do anything :
sed -n '/^12:00/,/^12:03/p' event.log > new_event.log

And the grep ones I believe will only extract lines that contain the pattern that I have entered. But they would miss the lines in between. I do need the lines without the pattern as well.

I again summarise my requirement:
In a file extract every thing from the first occurance of pattern: 12:01:00 till the last occurance of pattern: 12:03:00.

many thanks
ali
# 9  
Old 07-23-2009
I have no issues.
Is it possible your input file is DOS formatted?

Here is my working.
Code:
cat event.log
12:00:07 event 0 happened.
some line at 2
12:01:01 event 1 happened.
some line at 4
12:01:05 event 2 happened.
12:01:30 event 3 happened.
some line at 7
some line at 8
12:02:01 event 4 happened.
12:02:40 event 5 happened.
12:03:40 event 6 happened.
12:04:06 event 6 happened.

Command:
Code:
sed -n '/^12:00/,/^12:03/p' event.log

Output:
Code:
12:00:07 event 0 happened.
some line at 2
12:01:01 event 1 happened.
some line at 4
12:01:05 event 2 happened.
12:01:30 event 3 happened.
some line at 7
some line at 8
12:02:01 event 4 happened.
12:02:40 event 5 happened.
12:03:40 event 6 happened.

May be version issues?
Remove the "> new_event.log" part and check.
# 10  
Old 07-23-2009
PHP

Quote:
Originally Posted by alinaqvi90
I want to extract every thing in that file listed between a given start time and an end time.
.....
so some thing like all events between
the first entry of 12:01:00 and the last entry of 12:03:59

...and store them in a random text file. Note time stamps can be repeated and therefore I mentioned the first and the last entries.

And not all lines in the log file start with a time stamp.
Did you ever try my previous solution
# 11  
Old 07-23-2009
Quote:
Originally Posted by alinaqvi90
hi guys
Thanks for your replies so far

This pattern doesnt do anything :
sed -n '/^12:00/,/^12:03/p' event.log > new_event.log

And the grep ones I believe will only extract lines that contain the pattern that I have entered. But they would miss the lines in between. I do need the lines without the pattern as well.

I again summarise my requirement:
In a file extract every thing from the first occurance of pattern: 12:01:00 till the last occurance of pattern: 12:03:00.

many thanks
ali
Try with a gap before the "p" like this.
Code:
sed -n '/^12:00/,/^12:03/ p' event.log > new_event.log


Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extracting and copying text from one file to another

Helooo, So I have a .fasta file (a text file with sequence data) which looks like this, with just over 3 million lines of data. >TCONS_00000001 gene=XLOC_000001 AATTGTGGTGAAATGACTTCTGTTAACGGAGACATCGATGATTGTTGTTACTATTTGTTCTCAGGATTCA... (8 Replies)
Discussion started by: 4galaxy7
8 Replies

2. Shell Programming and Scripting

Extracting the column containing URL from a text file

I have the file like this: Timestamp URL Text 1331635241000 http://example.com Peoples footage at www.test.com,http://example4.com 1331635231000 http://example1.net crack the nuts http://example6.com 1331635280000 http://example2.net ... (0 Replies)
Discussion started by: csim_mohan
0 Replies

3. UNIX for Dummies Questions & Answers

Extracting lines from a text file based on another text file with line numbers

Hi, I am trying to extract lines from a text file given a text file containing line numbers to be extracted from the first file. How do I go about doing this? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

4. Shell Programming and Scripting

help extracting text from file

Hello I have a large file with lines beginning with 552, 553, 554, below is a small sample, I need to extract the data you can see below highlighted in bold from this file on the same location on every line and output it to a new file. Thank you in advance for any help 55201KL... (2 Replies)
Discussion started by: firefox2k2
2 Replies

5. UNIX for Dummies Questions & Answers

Extracting the last column of a text file

I would like to extract the last column of a text file but different rows of the text file have different numbers of columns. How do I go about doing that? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

6. UNIX for Dummies Questions & Answers

extracting text and reusing the text to rename file

Hi, I have some ps files where I want to ectract/copy a certain number from and use that number to rename the ps file. eg: 'file.ps' contains following text: 14 (09 01 932688 0)t the text can be variable, the only fixed element is the '14 ('. The problem is that the fixed element can appear... (7 Replies)
Discussion started by: JohnDS
7 Replies

7. Shell Programming and Scripting

Extracting a part of XML File

Hi Guys, I have a very large XML feed (2.7 MB) which crashes the server at the time of parsing. Now to reduce the load on the server I have a cron job running every 5 min.'s. This job will get the file from the feed host and keep it in the local machine. This does not solve the problem as... (9 Replies)
Discussion started by: shridhard
9 Replies

8. Shell Programming and Scripting

Extracting specific text from a file

Dear All, I have to extract a a few lines from a log file and I know the starting String and end string(WHich is same ). Is there any simplere way using sed - awk. e.g. from the following file -------------------------------------- Some text Date: 21 Oct 2008 Text to be extracted... (8 Replies)
Discussion started by: rahulkav
8 Replies

9. Shell Programming and Scripting

Extracting a line in a text file

If my file looks like this…. 10 20 30 and I want to take each line individually and put it in a variable so it can be read later in it's on individual test statement, how can I do that? I guess what I'm asking is how can I extract each line individually. Thanks (5 Replies)
Discussion started by: terryporter51
5 Replies

10. Shell Programming and Scripting

Extracting data from text file based on configuration set in config file

Hi , a:) i have configuration file with pattren <Range start no>,<Range end no>,<type of records to be extracted from the data file>,<name of the file to store output> eg: myfile.confg 9899000000,9899999999,DATA,b.dat 9899000000,9899999999,SMS,a.dat b:) Stucture of my data file is... (3 Replies)
Discussion started by: suparnbector
3 Replies

Featured Tech Videos