![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Adding a block to the file | ROOZ | Shell Programming and Scripting | 4 | 08-20-2008 04:34 PM |
| how to retreive a block of data from the file | aoussenko | Shell Programming and Scripting | 4 | 06-26-2008 11:03 AM |
| Deleting text block in file | andre123 | Shell Programming and Scripting | 1 | 02-27-2007 01:17 PM |
| Select last block from a file | misenkiser | Shell Programming and Scripting | 9 | 10-11-2006 09:32 AM |
| extract block in file | sskb | UNIX for Dummies Questions & Answers | 5 | 10-25-2001 10:29 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
help to get the block from a file
Code:
<Connection^M
companyId="TCS"^M
connectionMode="client"^M
name="TCS_TEMP"^M
protocolVersion="4.2"^M
disableLogging="false"^M
</Connection>
<Connection^M
companyId="HCL"^M
connectionMode="client"^M
name="HCL_RSDC02"^M
protocolVersion="4.2"^M
disableLogging="false"^M
</Connection>
<Connection^M
companyId="SCB"^M
connectionMode="server"^M
name="SCB_ERSDC02"^M
protocolVersion="4.1"^M
disableLogging="false"^M
connectionIntervals="08:00:00,18:00:00"^M
connectAtStartup="true"^M
</Connection>
<Connection^M
companyId="SAT"^M
connectionMode="client"^M
name="SAT_RSDC02"^M
protocolVersion="4.0"^M
disableLogging="false"^M
</Connection>
Any commands...? Code:
output should be
<Connection^M
companyId="SCB"^M
connectionMode="server"^M
name="SCB_ERSDC02"^M
protocolVersion="4.1"^M
disableLogging="false"^M
connectionIntervals="08:00:00,18:00:00"^M
connectAtStartup="true"^M
</Connection>
|
|
||||
|
Save this script, make it executable with chmod:
Code:
#!bin/sh
awk -v var="$1" '
/<Connection/{i=0}
{a[++i]=$0}
$0 ~ var {f=1}
/<\/Connection>/ && f {for(j=1;j<=i;j++){print a[j]};exit}
' file
Code:
./scriptname SCB_ERSDC02 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|