I have Some markdown text that I want to have replaced everytime I run a Shell script to get kubernetes information. Here is that markdown:
# Kube_cluster
| privateVlan | publicVlan | privateIP | publicIP | machineType | location | id | state | status | statusDate | statusDetails | errorMessage | errorMessageDate | isolation | kubeVersion | targetVersion | reasonForDelete | versionEOS | masterVersionEOS | trustedStatus | poolid | poolName | pendingOperation |
| --------------: | :------------- | :------------ | :----------- | :-------------- | :----------- | :----- | :-------- | :--------- | :------------- | :---------------- | :--------------- | :------------------- | :------------ | :-------------- | :---------------- | :------------------ | :------------- | :------------------- | :---------------- | :--------- | :----------- | :-------------------
9999999 | 6966666 | 0.0.0.212 | 10.257.257.42 | b3c.16x64.encrypted | dal10 | Kube-0000067d | normal | Ready | 2022-12-08T22:22:31+0000 | | | | private | 1.23.14_1553 | 1.23.14_1554 | | | | unsupported | okiedokie-1e501db | default |
9999999 | 6966666 | 0.0.0.195 | 10.257.257.82 | b3c.16x64.encrypted | dal10 | Kube-00001ab8 | normal | Ready | 2022-12-08T22:22:31+0000 | | | | private | 1.23.14_1553 | 1.23.14_1554 | | | | unsupported | okiedokie-1e501db | default |
9999999 | 6966666 | 0.0.0.249 | 10.257.257.74 | b3c.16x64.encrypted | dal10 | Kube-00001c81 | normal | Ready | 2022-12-08T22:22:32+0000 | | | | private | 1.23.14_1553 | 1.23.14_1554 | | | | unsupported | okiedokie-1e501db | default |
9999999 | 6966666 | 0.0.0.242 | 10.257.257.85 | b3c.16x64.encrypted | dal10 | Kube-00001d6b | normal | Ready | 2022-12-08T22:22:32+0000 | | | | private | 1.23.14_1553 | 1.23.14_1554 | | | | unsupported | okiedokie-1e501db | default |
9999999 | 6966666 | 0.0.0.194 | 10.257.257.90 | b3c.16x64.encrypted | dal10 | Kube-00001ea3 | normal | Ready | 2022-12-08T22:22:29+0000 | | | | private | 1.23.14_1553 | 1.23.14_1554 | | | | unsupported | okiedokie-1e501db | default |
9999999 | 6966666 | 0.0.0.251 | 10.257.257.66 | b3c.8x32.encrypted | dal10 | Edge-00001fde | normal | Ready | 2022-12-08T22:22:32+0000 | | | | public | 1.23.14_1553 | 1.23.14_1554 | | | | unsupported | okiedokie-de32bdc | edge |
9999999 | 6966666 | 0.0.0.198 | 10.257.257.68 | b3c.8x32.encrypted | dal10 | Edge-00002009 | normal | Ready | 2022-12-08T22:22:31+0000 | | | | public | 1.23.14_1553 | 1.23.14_1554 | | | | unsupported | okiedokie-de32bdc | edge |
9999999 | 6966666 | 0.0.0.207 | 10.257.257.94 | b3c.8x32.encrypted | dal10 | Edge-000021fa | normal | Ready | 2022-12-08T22:22:31+0000 | | | | public | 1.23.14_1553 | 1.23.14_1554 | | | | unsupported | okiedokie-de32bdc | edge |
## Addon Status
OK
Name Version Health State Health Status
addon1 1.0.0 normal Addon Ready.
addon2 1.14* (1.16 default) normal
---<br><br>
test
The object of this script is to replace the markdown table with another markdown table that has newer information.
I can find the Text i want to search for using this awk command (From the name of the cluster to ---<br><br>
):
test=Kube_cluster
replace=$(awk 'BEGIN {p=0};
/'$test'/ {p=1 ;next};
/---<br><br>/ {p=0;next};
p {print }' "md/$test.md" )
Now I run script again and I get different Markdown. That I want to replace in line the previous Markdown ( I want to replace the whole markdown block each run ):
# Kube_cluster
| privateVlan | publicVlan | privateIP | publicIP | machineType | location | id | state | status | statusDate | statusDetails | errorMessage | errorMessageDate | isolation | kubeVersion | targetVersion | reasonForDelete | versionEOS | masterVersionEOS | trustedStatus | poolid | poolName | pendingOperation |
| --------------: | :------------- | :------------ | :----------- | :-------------- | :----------- | :----- | :-------- | :--------- | :------------- | :---------------- | :--------------- | :------------------- | :------------ | :-------------- | :---------------- | :------------------ | :------------- | :------------------- | :---------------- | :--------- | :----------- | :-------------------
9999999 | 6966666 | 0.0.0.212 | 10.257.257.42 | b3c.16x64.encrypted | dal10 | Kube-0000067d | normal | Ready | 2022-12-08T22:22:31+0000 | | | | private | 1.23.15_15563 | 1.23.15_15564 | | | | unsupported | okiedokie-1e501db | default |
9999999 | 6966666 | 0.0.0.195 | 10.257.257.82 | b3c.16x64.encrypted | dal10 | Kube-00001ab8 | normal | Ready | 2022-12-08T22:22:31+0000 | | | | private | 1.23.15_15563 | 1.23.15_15564 | | | | unsupported | okiedokie-1e501db | default |
9999999 | 6966666 | 0.0.0.249 | 10.257.257.74 | b3c.16x64.encrypted | dal10 | Kube-00001c81 | normal | Ready | 2022-12-08T22:22:32+0000 | | | | private | 1.23.15_15563 | 1.23.15_15564 | | | | unsupported | okiedokie-1e501db | default |
9999999 | 6966666 | 0.0.0.242 | 10.257.257.85 | b3c.16x64.encrypted | dal10 | Kube-00001d6b | normal | Ready | 2022-12-08T22:22:32+0000 | | | | private | 1.23.15_15563 | 1.23.15_15564 | | | | unsupported | okiedokie-1e501db | default |
9999999 | 6966666 | 0.0.0.194 | 10.257.257.90 | b3c.16x64.encrypted | dal10 | Kube-00001ea3 | normal | Ready | 2022-12-08T22:22:29+0000 | | | | private | 1.23.15_15563 | 1.23.15_15564 | | | | unsupported | okiedokie-1e501db | default |
9999999 | 6966666 | 0.0.0.251 | 10.257.257.66 | b3c.8x32.encrypted | dal10 | Edge-00001fde | normal | Ready | 2022-12-08T22:22:32+0000 | | | | public | 1.23.15_15563 | 1.23.15_15564 | | | | unsupported | okiedokie-de32bdc | edge |
9999999 | 6966666 | 0.0.0.198 | 10.257.257.68 | b3c.8x32.encrypted | dal10 | Edge-00002009 | normal | Ready | 2022-12-08T22:22:31+0000 | | | | public | 1.23.15_15563 | 1.23.15_15564 | | | | unsupported | okiedokie-de32bdc | edge |
9999999 | 6966666 | 0.0.0.207 | 10.257.257.94 | b3c.8x32.encrypted | dal10 | Edge-000021fa | normal | Ready | 2022-12-08T22:22:31+0000 | | | | public | 1.23.15_15563 | 1.23.15_15564 | | | | unsupported | okiedokie-de32bdc | edge |
## Addon Status
OK
Name Version Health State Health Status
addon1 1.0.0 normal Addon Ready.
addon2 1.14* (1.16 default) normal
---<br><br>
test
Now to get the replacement value:
test=Kube_cluster
replace2=$(awk 'BEGIN {p=0};
/'$test'/ {p=1 ;next};
/---<br><br>/ {p=0;next};
p {print }' "md/$test.md" )
If I attempt a replace I get regular expression errors:
awk '{gsub(/'$replace'/,&'$replace2'); print}'
errors with
wk: illegal primary in regular expression | privateVlan | publicVlan | privateIP | publicIP | machineType | location | id | state | status | statusDate | statusDetails | errorMessage | errorMessageDate | isolation | kubeVersion | targetVersion | reasonForDelete | versionEOS | masterVersionEOS | trustedStatus | poolid | poolName | pendingOperation | at
source line number 1
Can a experienced Awk'r help me with what I'm doing incorrectly?
1st run of script you get the initial markdown (replace) ... Second run you get the same markdown file with the updated markdown. Where the entire first Initial markdown is replaced in the file with the replace2 markdown. Each run this file may contain other things in it... But the main goal is to search and find between tags and replace everything betweeen two tags with the new markdown table.
The expected result would be every time a run of the script is done... The Awk script would replace the text between the $test variable and --<br><br>
. not replacing the $Test variable or the --<br><br>
.
` ... those aren't the same; which is it ... *just* the `|`-delimited table or *all* lines between the markers? – markp-fuso Dec 09 '22 at 19:52