Select text between current date and output to new txt file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Select text between current date and output to new txt file
# 1  
Old 06-21-2012
Select text between current date and output to new txt file

Hi guys,
brand new to this thread and very very new to UNIX...so go easy please!

Anyway I have a file that looks like this:

Code:
>>--------------------------------------------------------------------------
Date/Time/Eng.   : 2012-06-22 / 00:26 /   DS
Reported problem : (SD)  
------------------------------------------------------------------------------

|00:26| 

Time/Date : 2012-06-22  00:26
Status    : UP
-----------------------------------------------------------------------------<<

>>--------------------------------------------------------------------------
Date/Time/Eng.   : 2012-06-22 / 00:29 / mole  DS
Reported problem : (SD)  test
SO               :       7
------------------------------------------------------------------------------

|00:29| 

Time/Date : 2012-06-22  00:30
Status    : UP, up as up can be in sydney
-----------------------------------------------------------------------------<<

2012-06-22>>--------------------------------------------------------------------------
Date/Time/Eng.   : 2012-06-22 / 00:33 / mole  DS
Reported problem : (SD)  lotabort
SO               :       4
------------------------------------------------------------------------------

|00:33| 

Time/Date : 2012-06-22  00:33
Status    : UP
-----------------------------------------------------------------------------<<

Which will follow this formatting throughout.
The current days entries will start with the date followed by >> and end in <<

What I need to do is select the text between these two "strings" and output it to another file.
What I have tried is

Code:
sed -n '/>>/,/<</p' log.doc > outputfile.doc

(can't seem to get the date to work but ideally I want this included, but for now I am just trying to figure out something that works.)

The problem with this is I think it starts at the beginning and stops once it has hit the first instance of the two strings.....what I need is the last entered "block" of this text to be selected and output to a file that will be overwritten daily.
Is there any way to do this? I have been googling + searching this site all night but either I can't understand the methods or no-one has had this exact issue.

Any help would be greatly appreciated!

Last edited by Scrutinizer; 06-22-2012 at 02:10 AM.. Reason: code tags instead of formatting
# 2  
Old 06-21-2012
Something with awk that might work for you:

Code:
awk '
    />>-+$/ {
        delete cache;
        ci = 0;
        snarf = 1;
    }
    snarf { cache[ci++] = $0 };
    /^-+<<$/ { snarf = 0; }

    END {
        for( i = 0; i < ci; i++ )
            print cache[i];
    }
' input-file >output-file

This User Gave Thanks to agama For This Post:
# 3  
Old 06-21-2012
Hi agama,

Thanks for your speedy reply...

I may have left out a huge detail...hopefully notSmilie

The command I am trying to run is being run through the shell command feature in NEdit on a solaris machine...I am guessing this makes this a whole different ball game?

When I enter that code intro the command and run it I get the following:
Code:
"Unmatched'
Variable syntax
delete: Command not found
ci: Command not found
snarf: Command not found
}: Command not found 
!No file for $0
Variable syntax
END: Command not found
Badly placed 0's
No match
}: Command not found
Unmatched'"

Sorry for failing to mention this earlier

Last edited by Scrutinizer; 06-22-2012 at 02:17 AM.. Reason: Added code tags ( + Removed image ????? )
# 4  
Old 06-22-2012
Well that's a new one on me -- not familiar with Nedit.

It sounds like a quoting problem, but I don't have access to a Solaris box at the moment, so I cannot poke from that angle. I do know that with solaris' version of awk you'll need to change delete cache to split( "", cache, "." ). It 'empties' the array -- that version of awk doesn't support delete. You also probalby want to use nawk or (I think) /usr/xpg4/bin/awk.

Can you save the awk script to a file, and then try running the file from Nedit? That's probably the only thing I can think to suggest without knowing the Nedit environment.

There are plenty of folks who work on Solaris more regularly than I do -- be patient I'm sure one of them will offer something that might be of more help.

Sorry.
This User Gave Thanks to agama For This Post:
# 5  
Old 06-22-2012
Somehow that awk code is not protected from the shell, because it does not get run as awk code but it is run by the shell. Those are shell error messages, not awk...
It may be that every line is interpreted as separate (because the first error messages says "Unmatched' .

Does it do this also with this alternative one-liner?
Code:
/usr/xpg4/bin/awk 'f{p=p RS $0} />>--/{p=$0}{f=1} /--<</{f=0} END{print p}' infile


S.

Last edited by Scrutinizer; 06-22-2012 at 11:08 AM..
This User Gave Thanks to Scrutinizer For This Post:
# 6  
Old 06-22-2012
Thanks Scrutinizer,

I used the changes agama suggested, saved as passdown.sh, uploaded to machine, ran
Code:
chmod +x passdown.sh

Then as super user ran
Code:
./passdown.sh

and it worked.

So from running it like this I have no problems, but are your suggestions a way of running it in NEdit?

How can I get this to run from NEdit?

Thanks for your input also!

---------- Post updated at 05:24 PM ---------- Previous update was at 04:03 PM ----------

@scrutinizer
Just tried that from the run shell command part of NEdit and it worked!

I'll have to man all that code but thanks for your help!!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to replace a parameter(variable) date value inside a text files daily with current date?

Hello All, we what we call a parameter file (.txt) where my application read dynamic values when the job is triggered, one of such values are below: abc.txt ------------------ line1 line2 line3 $$EDWS_DATE_INSERT=08-27-2019 line4 $$EDWS_PREV_DATE_INSERT=08-26-2019 I am trying to... (1 Reply)
Discussion started by: pradeepp
1 Replies

2. UNIX for Beginners Questions & Answers

“sed” replace date in text file with current date

We want to call a parameter file (.txt) where my application read dynamic values when the job is triggered, one of such values are below: abc.txt ------------------ Code: line1 line2 line3 $$EDWS_DATE_INSERT=08-27-2019 line4 $$EDWS_PREV_DATE_INSERT=08-26-2019 I am trying to write a... (3 Replies)
Discussion started by: pradeepp
3 Replies

3. Shell Programming and Scripting

Desired output.txt for reading txt file using awk?

Dear all, I have a huge txt file (DATA.txt) with the following content . From this txt file, I want the following output using some shell script. Any help is greatly appreciated. Greetings, emily DATA.txt (snippet of the huge text file) 407202849... (2 Replies)
Discussion started by: emily
2 Replies

4. Windows & DOS: Issues & Discussions

2 Questions: replace text in txt file, add text to end of txt file

so... Lets assume I have a text file. The text file contains multiple "#" symbols. I want to replace all thos "#"s with a STRING using DOS/Batch I want to add a certain TEXT to the end of each line. How can I do this WITHOUT aid of sed, grep or anything linux related ? (1 Reply)
Discussion started by: pasc
1 Replies

5. Shell Programming and Scripting

Need to append the date | abcddate.txt to the first line of my txt file

I want to add/append the info in the following format to my.txt file. 20130702|abcd20130702.txt FN|SN|DOB I tried the below script but it throws me some exceptions. <#!/bin/sh dt = date '+%y%m%d'members; echo $dt+|+members+$dt; /usr/bin/awk -f BEGIN { FS="|"; OFS="|"; } { print... (6 Replies)
Discussion started by: harik1982
6 Replies

6. UNIX for Dummies Questions & Answers

Putting the Current -date in the Output File

Hi guys, Just want to ask how can I make a script that will perform like this. 1. Execute the command 2. Then the output of the command will be redirected to a file 2. The file that has been created will have a date on it equivalent to the date and time it was created (or maybe after the... (5 Replies)
Discussion started by: rymnd_12345
5 Replies

7. UNIX for Dummies Questions & Answers

Comparing Output Date to Current System Date

Hi Guys, Anyone who knows how to compare the current date with the a file containing a date, say for example I have a file that looks like this: Command was launched from partition 0. ------------------------------------------------ Executing command in server server6 Fri Dec 16... (7 Replies)
Discussion started by: rymnd_12345
7 Replies

8. UNIX for Dummies Questions & Answers

Move txt file to with current date appended to filename

I have multiple txt files which begin with the word "orders" in folder C:\source. I need to move the files to folder C:\dest and rename them to "process_<date>_<count>" So for example , if there are 3 files ordersa.txt , ordersb.txt and ordersc.txt in C:\source , after running the script I want... (7 Replies)
Discussion started by: johannd
7 Replies

9. Shell Programming and Scripting

Move txt file to with current date appended to filename

I have multiple txt files which begin with the word "orders" in folder C:\source. I need to move the files to folder C:\dest and rename them to "process_<date>_<count>" So for example , if there are 3 files ordersa.txt , ordersb.txt and ordersc.txt in C:\source , after running the script I want... (1 Reply)
Discussion started by: johannd
1 Replies

10. Shell Programming and Scripting

how to create file.txt and add current date in file content

Hey guy, how to make bash script to create foo.txt file and add current date into file content and that file always append. example: today the script run and add today date into content foo.txt and tomorrow the script will run and add tomorrow date in content foo.txt without remove today... (3 Replies)
Discussion started by: chenboly
3 Replies
Login or Register to Ask a Question