- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Joining Lines after pattern search
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
Forums
Discussions
Discussions
Discussions
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
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
08-30-2004 04:26 AM
08-30-2004 04:26 AM
Joining Lines after pattern search
Is there a way to join several lines every time a pattern is found for e.g
(Disp is a tool to convert binary in a readable format for e.g the output would look like
DSB=fb 00 80 00 01 0a 011616527100 0000 0000 04081c141833 0a 011450225000000000
+++= 00000010001c0000002d20000101ac024000ad0414001400064a4744484142ce
+++= 02aa03041023ab08454e5155495234201702e3172d20000000000000009b7500)
Disp Filename | awk '{if($1~/^Chris/){
hexstr="0123456789abcdef"
newnum=tolower(substr($8,3,2) substr($8,1,2))
MONT=tolower(substr($10,3,2))
....
....
}
}
if($1~/^DSB/){
#--> here I get stuck trying to add "+++=" to every /DSB/ found, because it belongs in the same line. I can use the following statement in a different awk patterns, but certain files contain both Chris and DSB and some only DSB.
awk '/DSB=/{printf "%s%s",sep,$0;sep="\n";next}
{printf "%s",$0}
END{print}' | awk '/DSB/{
hexstr="0123456789abcdef"
newnum=tolower(substr($4,3,2) substr($4,1,2))
MONT=tolower(substr($10,3,2))
....
....
}
}'
Many Thanks
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2004 04:44 AM
08-30-2004 04:44 AM
Re: Joining Lines after pattern search
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2004 04:51 AM
08-30-2004 04:51 AM
Re: Joining Lines after pattern search
Disp Filename | perl -ne 'chomp; print $nl if /^DSB/; print $_; $nl="\n";' -e 'print "\n";'
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2004 04:53 AM
08-30-2004 04:53 AM
Re: Joining Lines after pattern search
Disp Filename | perl -ne 'chomp; print $nl if /^DSB/; print $_; $nl="\n";' -e 'END{print "END\n";}'
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2004 05:17 AM
08-30-2004 05:17 AM
Re: Joining Lines after pattern search
Thanks for the reply.
The before snippet is
1)DSB=fb 00 80 00 01 0a 011616527100 0000 0000 04081c141833 0a 011450225000000000
2)+++=00000010001c0000002d20000101ac024000ad0414001400064a4744484142ce
3)+++=02aa03041023ab08454e5155495234201702e3172d20000000000000009b7500
4)DSB=fb 00 80 00 01 0a 039254023500 0000 d801 04081c141834 0a 031462586600000000
5)+++=0000001000180000001720000102ac026000ad041b001a000644544d484142b9
6)
+++=000b
This is were I have a problem in joining these lines. What it should look like before I define (newnum=tolower(substr($4,3,2) substr($4,1,2))
Pionts 1 to 3 is a record for e.g
DSB=.. .. .. .. .. +++=.. .. .. ... .. .. +++= .... .. .. .. .. .. .. ..
DSB=.. .. .. .. .. +++=.. .. .. .. +++=.. .. ... is the next record.
Please note that I first search for /Chris/ and then define etc but when the next record starts with ^DSB I use the /DSB/ and define ( as shown in my previous post)so that my output could look like plain simple text format for both Chris and DSB for e.g.
And the result whould be
0116165271 2004-08-28 20:24:51 0114502250 0
Many Thanks
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2004 05:26 AM
08-30-2004 05:26 AM
Re: Joining Lines after pattern search
I'm still not sure what you want to do WITH the data, but this script will combine the lines for you and then you can put your magic in the two spots where I have "Do Stuff" listed.
BEGIN {started=0;}
/^DBS/ {if (started > 0 )
{Do stuff };
started=1; keptline=$0;
next;}
{keptline=keptline $0;}
END {Do stuff}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2004 05:40 AM
08-30-2004 05:40 AM
Re: Joining Lines after pattern search
Thanks
Part of my Script looks like this
$RAW $2 |awk '{
if($1~/Chris/){
for (e=1;e
{if ($(e+4)==00){
Anum="NULL"
}else{
A_num=$(e+5)
}}}
if($e~/P=65/){
BNUM=$(e+2)
LN=$(e+1)
}
if($e~/P=64/){
DATE=$(e+1)
DUR=$(e+3)
}
if($e~/P=67/){
UN=$(e+1)
}}
hexstr="0123456789abcdef"
newnum=tolower(substr(DUR,5,2) substr(DUR,3,2) substr(DUR,1,2))
YEAR=tolower(substr(DATE,1,2))
MONT=tolower(substr(DATE,3,2))
DAY=tolower(substr(DATE,5,2))
HOUR=tolower(substr(DATE,7,2))
................
printf ("%15s %.2d-%.2d-%.2d %.2d:%......
}
}
if($1~/DSB=/){
hexstr="0123456789abcdef"
newnum=tolower(substr($9,3,2) substr($9,1,2))
YEAR=tolower(substr($10,1,2))
MONT=tolower(substr($10,3,2))
DAY=tolower(substr($10,5,2))
HOUR=tolower(substr($10,7,2))
MIN=tolower(substr($10,9,2))
...........................
printf ("%11s %.2d-%.2d-%.2d %.2d:%.2d:%.2
}
}'
Please note that Chris format differs to the DSB one and yes to your answer, after the +++= there is additional info that I require.
How could I use your script in this case????
Thanks Once Agaqin
Chris