Skip to main content
deleted 125 characters in body
Source Link
user232326
user232326

This may be of help:

#!/bin/bash

awk -vtag=instance -vp=0 '{
if($0~("^<"tag)){p=1;next}
if($0~("^</"tag)){p=0;printf("\n");next}
if(p==1){$1=$1;printf("%s",$0)}
}' infile 

Assuming the SampleSample text in your example is a mistake and keeping it simplersimple.

The p variable decides when to print what has been accumulated in variable val. On closing tag (assumed "instance") the value is printed and val is reset to empty. A $1=$1 removes leading spaces.

This may help:

#!/bin/bash

awk -vtag=instance -vp=0 '{
if($0~("^<"tag)){p=1;next}
if($0~("^</"tag)){p=0;printf("\n");next}
if(p==1){$1=$1;printf("%s",$0)}
}' infile 

Assuming the Sample text in your example is a mistake and keeping it simpler.

The p variable decides when to print what has been accumulated in variable val. On closing tag (assumed "instance") the value is printed and val is reset to empty. A $1=$1 removes leading spaces.

This may be of help:

#!/bin/bash

awk -vtag=instance -vp=0 '{
if($0~("^<"tag)){p=1;next}
if($0~("^</"tag)){p=0;printf("\n");next}
if(p==1){$1=$1;printf("%s",$0)}
}' infile 

Assuming the Sample text in your example is a mistake and keeping it simple.

The p variable decides when to print. A $1=$1 removes leading spaces.

Simpler code, no spaces.
Source Link
user232326
user232326

This may help:

#!/bin/bash

awk -vtag=instance -vp=0 '{
if($0~"<"tag$0~("^<"tag)){p=1;next}
if($0~"\\<"tag$0~("^</"tag)){p=0;printf("%s\n",val"\n");val="";next;next};
val=val$0if(p==1){$1=$1;printf("%s",$0)}
}' infile 

Assuming the Sample text in your example is a mistake and keeping it simpler.

The p variable decides when to print what has been accumulated in variable val. On closing tag (assumed "instance") the value is printed and val is reset to empty. A $1=$1 removes leading spaces.

This may help:

#!/bin/bash

awk -vtag=instance -vp=0 '{
if($0~"<"tag){p=1;next}
if($0~"\\<"tag){p=0;printf("%s\n",val);val="";next};
val=val$0
}' infile 

Assuming the Sample text in your example is a mistake and keeping it simpler.

The p variable decides when to print what has been accumulated in variable val. On closing tag (assumed "instance") the value is printed and val is reset to empty.

This may help:

#!/bin/bash

awk -vtag=instance -vp=0 '{
if($0~("^<"tag)){p=1;next}
if($0~("^</"tag)){p=0;printf("\n");next}
if(p==1){$1=$1;printf("%s",$0)}
}' infile 

Assuming the Sample text in your example is a mistake and keeping it simpler.

The p variable decides when to print what has been accumulated in variable val. On closing tag (assumed "instance") the value is printed and val is reset to empty. A $1=$1 removes leading spaces.

Source Link
user232326
user232326

This may help:

#!/bin/bash

awk -vtag=instance -vp=0 '{
if($0~"<"tag){p=1;next}
if($0~"\\<"tag){p=0;printf("%s\n",val);val="";next};
val=val$0
}' infile 

Assuming the Sample text in your example is a mistake and keeping it simpler.

The p variable decides when to print what has been accumulated in variable val. On closing tag (assumed "instance") the value is printed and val is reset to empty.