|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 01:10 AM.. Reason: code tags instead of formatting |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
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 |
| The Following User Says Thank You to agama For This Useful Post: | ||
martin0852 (06-22-2012) | ||
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Hi agama, Thanks for your speedy reply... I may have left out a huge detail...hopefully not ![]() 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 01:17 AM.. Reason: Added code tags ( + Removed image ????? ) |
|
#4
|
|||
|
|||
|
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. |
| The Following User Says Thank You to agama For This Useful Post: | ||
martin0852 (06-22-2012) | ||
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
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}' infileS. Last edited by Scrutinizer; 06-22-2012 at 10:08 AM.. |
| The Following User Says Thank You to Scrutinizer For This Useful Post: | ||
martin0852 (06-22-2012) | ||
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
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!! |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Putting the Current -date in the Output File | rymnd_12345 | UNIX for Dummies Questions & Answers | 5 | 12-22-2011 04:32 AM |
| Comparing Output Date to Current System Date | rymnd_12345 | UNIX for Dummies Questions & Answers | 7 | 12-16-2011 04:17 PM |
| Delete a row from a file if one column containing a date is greater than the current system date | chumsky | UNIX for Dummies Questions & Answers | 4 | 07-06-2011 02:07 AM |
| Prefix the current date and time to the output of ps | Bloke | Shell Programming and Scripting | 2 | 04-08-2009 08:25 AM |
| Perl: Extracting date from file name and comparing with current date | MKNENI | Shell Programming and Scripting | 4 | 03-26-2008 04:01 PM |
|
|