- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Cut part of txt file with specified terms....
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-13-2010 01:12 AM
тАО04-13-2010 01:12 AM
00000000.3987 2010-04-13 09:04:22 argv[0]: './encrypt'
00000000.3987 2010-04-13 09:04:22 argv[1]: './'
And end with: (B)
00000014.9556 2010-04-13 09:00:21 SendMessage: wiadomosc wyslana
00000015.1078 2010-04-13 09:00:22 wiadomosc wyslana
00000015.1078 2010-04-13 09:00:22 ~Message()
But sometime i have error (C):
00000006.3951 2010-04-13 09:04:28 Encrypt ret: 7
00000006.3951 2010-04-13 09:04:28 blad szyfrowania
00000006.3951 2010-04-13 09:04:28 ~Message()
Normal pass is: (A) ..... (B) etc....
Error: (A) ..... (C) (no B here !)
I need to get:
1. All errors from file - section A -> C (there are no B in this pass), but without any normal, sucessfull termination (section A->B)
2. Only last error pass.
Can i do this with sed command?
To cut all errors, only one A-C per error ?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-13-2010 01:15 AM
тАО04-13-2010 01:15 AM
Re: Cut part of txt file with specified terms....
A - unique in this section is
argv[0]: './encrypt'
C - unique text is
Encrypt ret: 7
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-13-2010 12:42 PM
тАО04-13-2010 12:42 PM
Re: Cut part of txt file with specified terms....
This seems much too complex for sed. awk may be better.
>To cut all errors, only one A-C per error?
You are going to have to provide much more details, actual files. I'm not sure what is A, B or C.
Perhaps this is easier, what do you not want?
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-13-2010 12:50 PM
тАО04-13-2010 12:50 PM
Re: Cut part of txt file with specified terms....
1. normall pass:
start with section A, next some other lines... and end with B.
2. Pass with error: starti with A, some other lines... end with C.
Of course, as normal program function there are many A-B in log and only few with A-C.
I need to cut only sections with A-C and throw away all A-B.
When i trying something like
sed -n -e '1,/argv\[0\]: /p' -e '1,/Encrypt ret: 7/p' plik.txt
i get start with A.... (first from start of file) to first error - C section. But with all A-B in this file. I must remove them.
Best is cut on first C section and go backwards line by line untill i get first A section.
But i dont know to do it :/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-13-2010 01:15 PM
тАО04-13-2010 01:15 PM
Re: Cut part of txt file with specified terms....
What varies?
>Best is cut on first C section and go backwards line by line until I get first A section.
Backwards doesn't work well unless you have arrays, with awk or perl.
Do you have some example data?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-13-2010 01:24 PM
тАО04-13-2010 01:24 PM
Re: Cut part of txt file with specified terms....
This is different. Dont look at date.
Sections like "00000000.3987 2010-04-13 09:04:22" is always different. Number of lines between beginning and end is always different.
I want to focus on:
argv[0]: './encrypt'
Encrypt ret: 7
SendMessage: wiadomosc wyslana
Upper words is unique in logs. If i try to catch all lines between it, it will work fine.
>Do you have some example data?
There are some data, also uuencoded area. This is log from delta encryptor - so i cannot post all of them.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-13-2010 01:50 PM
тАО04-13-2010 01:50 PM
Re: Cut part of txt file with specified terms....
Dennis asked you "How many lines are in A, B and C, exactly like you have except for the leading dates/time?"
You haven't answered this question. Are there always some set number of lines to A, B and/or C? Is there some specific delimiter between A, B, and C as for example a blank line?
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-13-2010 02:46 PM
тАО04-13-2010 02:46 PM
Re: Cut part of txt file with specified terms....
You might try playing and adapting something like this:
# cat ./extract
#!/usr/bin/perl
use strict;
use warnings;
my $AVAL='a'; #...change to what you want to match...
my $BVAL='b'; #...ditto
my $CVAL='c'; #...ditto
my ( @list, $rangeop );
sub spout {
#...the list must contain $AVAL and $CVAL to be a candidate...
@list = grep( !/$BVAL/, @list );
if ( grep( /$CVAL/, @list ) ) {
print ">>> $_\n" for @list;
}
@list=();
}
while (<>) {
chomp;
if ( $rangeop = /$AVAL/../$CVAL/ ) {
@list = () if /$AVAL/;
push @list, $_;
}
if ($rangeop =~ m/E0/) { #...signifies range's end...
spout();
}
}
END {
spout();
}
1;
...which if run interactively (where lines with ">>> " are the output generated at that point in the line-by-line input) would look like:
# ./extract
a
b
a
b
c
>>> a
>>> c
aaa
xxx
yyy
zzz
bbb
bbb
ccc
>>> aaa
>>> xxx
>>> yyy
>>> zzz
>>> ccc
a
c
>>> a
>>> c
a
b
a
a
a
b
b
c
>>> a
>>> c
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-13-2010 06:22 PM
тАО04-13-2010 06:22 PM
Solutionawk '
BEGIN { count=0; collect=0 }
function print_lines() {
for (i = 1; i <= count; ++i)
print save[i]
count = 0;
}
function save_line() {
save[++count] = $0
}
/argv\[0]:/ { # A start
collect = 1
save_line()
next
}
/Encrypt ret: 7/ { # C error
save_line() # save 3
getline; save_line()
getline; save_line()
print_lines()
collect = 0
next
}
/SendMessage: wiadomosc wyslana/ { # B normal
getline; getline # flush 3
count = 0
collect = 0
next
}
collect {
save_line()
next
}' input-file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-13-2010 11:21 PM
тАО04-13-2010 11:21 PM