PlantUml: How to do a multiline display in opt condition for sequence diagram - plantuml

Im trying to do a UML diagram for a script below in PlantUML.
[plantuml, target=diagram-sequence, format=png]
....
#startuml
-> A: test
opt ((Exterme_DANGER_Forwith_cIES_MICRO_GYRO) || (Exterme_DANGER_Forwith_cIES_PANASONIC_GYRO) || (Exterme_DANGER_Forwith_cIES_VIRTUAL) || (Exterme_DANGER_Forwith_cIES_Cobra) || (Exterme_DANGER_Forwith_cIES_VTI) || (Exterme_DANGER_Forwith_cIES_VTI_SPI) || (Exterme_DANGER_Forwith_cIES_VIRTUAL) || (Exterme_DANGER_Forwith_cIES_VTI) || (Exterme_DANGER_Forwith_cIES_VTI_SPI) || (Exterme_DANGER_Forwith_cIES_VIRTUAL)) || (Exterme_DANGER_Forwith_cIES_Cobra5) || (Exterme_DANGER_Forwith_cIES_Cobra4))
<- A
end opt
#enduml
....
When I do this I cannot see the complete diagram.
Does anyone know of a way to show the big opt conditon in multiple lines in the diagram?

Adding newlines \n will break the opt across multiple lines in the diagram, but it will still be on one in the PlantUML text file, which can be hard to read.
To make things more readable, adding \ at the end of the line will allow splitting text across multiple lines.
Combining \n with \ allow splitting the single line across multiple lines in both the diagram and the file:
#startuml
-> A: test
opt ( \
(Exterme_DANGER_Forwith_cIES_MICRO_GYRO) \n\
|| (Exterme_DANGER_Forwith_cIES_PANASONIC_GYRO)\n\
|| (Exterme_DANGER_Forwith_cIES_VIRTUAL) \n\
|| (Exterme_DANGER_Forwith_cIES_Cobra) \n\
|| (Exterme_DANGER_Forwith_cIES_VTI) \n\
|| (Exterme_DANGER_Forwith_cIES_VTI_SPI) \n\
|| (Exterme_DANGER_Forwith_cIES_VIRTUAL) \n\
|| (Exterme_DANGER_Forwith_cIES_VTI) \n\
|| (Exterme_DANGER_Forwith_cIES_VTI_SPI) \n\
|| (Exterme_DANGER_Forwith_cIES_VIRTUAL)) \n\
|| (Exterme_DANGER_Forwith_cIES_Cobra5) \n\
|| (Exterme_DANGER_Forwith_cIES_Cobra4) \n\
)
<- A
end opt
#enduml

Related

Linux Bash: how to compare VAR with characters pool?

I have the text file with the elements of Periodic table, looking like
1 H *Name of element in 1 language* *Second l-ge* *Third* etc
2 He *Name of element in 1 language* *Second l-ge* *Third* etc
etc
(with names of the elements in different human languages)
And I need to remove all the words excluding only 1 target language, and for that I need to know how to compare STRING with array of characters (so that if none of the array letters would be matched with the comparing WORD from the textfile, this word wouldn't be printed).
Could anyone help with that?
More details / How I tried to solve this:
The first problem I encounter is that I don't know how to compare VAR with array of characters:
I wrote something like this:
#!/bin/sh
#PeriodicTable1
counter=0
while [ "$counter" -le "$#" ] ; do
counter=$(( $counter+1 )) ;
if [ "${$counter}" == *[1234567890abcdefghigklmn and etc, so here all the characters from the language that is not removing right now]* ] ; then
echo "${$counter}" ;
done
to run ./PeriodicTable1 OPTION1 OPTION2 OPT3 OPT4 etc (where options are text from the text file)\
and to get the words from text as options $1 $2 $3 etc, until $#\
and to compare them with the array of characters from language that has been chosen to be saved\
and just after (if it would work) I would use ">" to redirect output into a text file
So If the text in the file would be like this: 1 H Hydrogen Wasserstoff Hydrogène 氢 and if I would be needed to save only
Chinese, then I would typed in Terminal ./PeriodicTable1.sh 1 H Hydrogen Wasserstoff Hydrogène 氢 and would be expecting output like
this: 1 H 氢 by removing all other stuff 'cuz characters in the
words (as the options of a command) wouldn't match the Chinese
character --> wouldn't be printed
Then I wrote something like
#!/bin/sh
#PeriodicTable2
for WORD in (and here is the whole text) ; do
if [ "$WORD" == *[straight line of characters]* ; echo "$WORD" ;
done
and then
#!/bin/sh
#PeriodicTable3
counter=1 ;
save={1,2,3,4,5,6,7,8,9,0,a,b,c,d, etc} ;
while [ "$counter" -le "$#" ] ; case "${$counter}" in
*"$save"*)
echo ${$counter} ;
counter=$(( $counter+1 )) ;
;
esac
and then
#!/bin/sh
#PeriodicTable4
counter=1 ;
save={a,b, etc}
while [ "${0+$counter}" -le "$#" ] ; {
if [ "${0+$counter}" == *"$save"* ] echo "${0+$counter}" ;
counter=$(( $counter+1 )) ;
}
but nor a one of these script routines does work
and the second problem is that that if there are need to save a nonEnglish language, then letters of elements would be disappearing; but I guess that with that I could be handling, if for the first problem solution would be founded...
UPDATE:
Solution is still unfound, but I found that task already could be
done by
awk command
awk '{print $number_of_word1_in_line, $n2, $n3}'
With counting words by $var and printing only those which positions are equal to their number in line + X*n, where X is the number of words between the lines and n is var in {1..total_number_of_lines}\
With tr command
tr -c a-zA-Z '\n' < someFile.txt | sed '/^$/d'
I think you are looking for logic along the lines of what I have put together below. NOTE: I have re-formatted the input file, because it is better to have a fixed character (that would never be used in any field) as a delimiter.
As an exercise, I created my own raw table with many more languages populated (in a LibreOffice ODS file, then exported with the bars; I can provide that if you want), from which I rebuilt the modified version of your table, where I used the vertical bar (|) as the safe delimiter.
The logic was also expanded to use the first line to assign the input format values into the "cols" array, and in so doing allowing the script to adapt to the format of the input file (variations of column assignments/contents) but still output based on the specified language using --language flag.
If interested, the source of the info I extracted came from the corresponding pages identified here.
Lastly, Persian goes right-to-left, contrary to others in your table going from left-to-right. The print statement does the context-driven justification based on column position, but that info could be provided on a second header line, and parsed accordingly for output formatting.
Hope this addresses your needs!
#!/bin/sh
### QUESTION: https://stackoverflow.com/questions/74234471/linux-bash-how-to-compare-var-with-characters-pool
DBG=0
while [ $# -gt 0 ]
do
case $1 in
--language ) tLANG=$2 ; shift ; shift ;;
--debug ) DBG=1 ; shift ;;
* ) echo "\n\t Invalid option specified on the command line. Only valid: [ --language {} ] \n Bye!\n" ; exit 1 ;;
esac
done
if [ -z "${tLANG}" ] ; then echo "\n\t Language specification required on the command line. \n\n\t Usage: $0 --language [ English | Italian | Greek | Polish | French | Persian ]\n" ; exit 1 ; fi
### Format of ELEMENTS_TABLE
#Z Symbol English Italian Greek Polish French Persian
ELEMENTS_TABLE="Elements_table.csv"
### Format of ELEMENTS_RAW
#1 |2 |3___________________
#____|4 |5 |6 |7 |8 |9 |10 |11 |12 |13 |14 |15 |16 |17 |18 ||20 |21 |22 |23
#Atomic Number|Symbol|Atomic Mass (amu, g/mol)|Latin|ALTERNATE|English|Greek|German|French|Italian|Spanish|Polish|Turkish|Russian|Afrikaans|Sesotho|Chinese|Hindi||Japanese|Hebrew|Arabic|Persian
### Position Mapping for Requestor: 1 2 6 10 7 12 9 23
#ELEMENTS_RAW="Elements_details.csv"
#awk -F \| '{
# printf("%s|%s|%s|%s|%s|%s|%s|%s|\n", $1, $2, $6, $10, $7, $12, $9, $23 ) ;
#}' < "${ELEMENTS_RAW}" >"${ELEMENTS_TABLE}"
### Match on language position
#echo $tLANG
awk -F \| -v lang="${tLANG}" -v debug="${DBG}" '\
BEGIN{
getline header ;
if( debug == 1 ){
print header ;
} ;
n=split( header, cols, "|") ;
if( debug == 1 ){
for( pos=1 ; pos <= 8 ; pos++ ){
print cols[pos] ;
} ;
} ;
#cols[1]="Z" ;
#cols[2]="Symbol" ;
#cols[3]="English" ;
#cols[4]="Italian" ;
#cols[5]="Greek" ;
#cols[6]="Polish" ;
#cols[7]="French" ;
#cols[8]="Persian" ;
lCOL=0 ;
for( pos=1 ; pos <= 8 ; pos++ ){
if( debug == 1 ){
print "cols[", pos, "] = ", cols[pos] ;
} ;
if( cols[pos] == lang ){
lCOL=pos ;
} ;
} ;
if( lCOL == 8 ){
printf("%-4s %-6s %15s\n", cols[1], cols[2], cols[lCOL] ) ;
}else{
printf("%-4s %-6s %-s\n", cols[1], cols[2], cols[lCOL] ) ;
} ;
}{
#printf("%-4s %-3s %-s %-10.7f\n", $1, $2, $lCOL, $3 ) ;
if( lCOL == 8 ){
printf("%-4s %-6s %15s\n", $1, $2, $lCOL ) ;
}else{
printf("%-4s %-6s %-s\n", $1, $2, $lCOL ) ;
} ;
}' <${ELEMENTS_TABLE}

if a 2 strings BOTH present in 1 array in a bash script

I have 2 strings "planning1" and "planning2" , I have to check if both the strings are present (whole and complete) in the same array ("active","planning","delete")
expected output: if both the strings present -> echo "true"
even if one of the string is not present in the list then -> echo "false"
I have previously tried , but it does not work as expected
#!/bin/bash
declare -a test_array
test_array=( "active" "teardown" "planning" )
[[ " $test_array " =~ " active " ]] && [[ " $test_array " =~ " planning " ]] && echo 'yes' || echo 'no'
This is a case where interpolation of the entire array to a single string might be handy.
You can do that with * as the subscript.
edit
Added delimiting spaces around the array and the pattern.
You could make this more precise, and modifying $IFS may change the bahviour - unless quoted, Bash splits input to words based on $IFS, which defaults to whitespace but you can modify it.
$: ray=( "active" "teardown" "planning" )
$: [[ " ${ray[*]} " =~ ' active ' && " ${ray[*]} " =~ ' passive' ]] && echo found || echo no
no
$: [[ " ${ray[*]} " =~ ' active ' && " ${ray[*]} " =~ ' planning ' ]] && echo found || echo no
found

Displaying one index in an array, while storing the entire entry

The title could suck, not sure what a good way to explain it is.
This might both be a bad idea, but I'm trying to make a kind of ninite-thing for Linux/Ubuntu. I want a correctly styled name to appear in the list where you check what you want to install, whereas the package name is needed for installation. I have tried to achieve this, but not had much luck.
The menu/interactive bits have been taken from this site. I have only added arrays as options, and a few other modifications. I am very new to this, and it is mainly a project for learning.
#!/bin/bash
# customize with your own.
#Packages
filezilla=("FileZilla" "filezilla" "ftp")
nmap=("Nmap" "nmap" "network_tools")
linssider=("LinSSIDer" "linssider" "network_tools")
wireshark=("Wireshark" "wireshark" "network_tools")
atom=("Atom" "atom" "editor")
vim=("Vim" "vim" "editor")
steam=("Steam" "steam" "chat")
streamlink=("Streamlink GUI" "streamlink" "media")
whois=("Whois" "whois" "network_tools")
htop=("Htop" "htop" "monitoring")
traceroute=("Traceroute" "traceroute" "network_tools")
options=(
"${filezilla[0]}"
#echo Network Tools
"${nmap[0]}"
"${linssider[0]}"
"${wireshark[0]}"
"${whois[0]}"
"${htop[0]}"
"${traceroute[0]}"
#echo "Text Editor"
"${atom[0]}"
"${vim[0]}"
#echo "Chat"
"${steam[0]}"
#echo "Media"
"${streamlink[0]}"
#select all in category x
#select all in cat y
)
#render list
clear
menu() {
echo ""
echo "What do you want to install:"
for i in ${!options[#]}; do
printf "%3d%s) %s\n" $((i+1)) "${choices[i]:- }" "${options[i]}"
done
[[ "$msg" ]] && echo "$msg"; :
}
#selecting
prompt="Check an option (again to uncheck, ENTER when done): "
while menu && read -rp "$prompt" num && [[ "$num" ]]; do
clear
[[ "$num" != *[![:digit:]]* ]] &&
(( num > 0 && num <= ${#options[#]} )) ||
{ msg="Invalid option: $num"; continue; }
((num--)); msg="${options[num]} was ${choices[num]:+un}checked"
[[ "${choices[num]}" ]] && choices[num]="" || choices[num]="+"
done
#what was selected
printf "You selected"; msg=" nothing"
for i in ${!options[#]}; do
[[ "${choices[i]}" ]] && { printf " \n%s" "${options[i]}"; msg=""; }
echo ${choices[1]}
done
echo "$msg"
#install selected
#sudo apt install -y update ${choices[1]}

Using Ternary operator to assign an array to another variable in bash

I have two arrays in a bash script
say
ConfigA=("hostname1" "hostname2")
ConfigB=("hostname3" "hostname4")
Now I am passing an argument to the script specifying which Array I need to work with
For that I came up with a bash equivalent of ternary operator like below
int a = (b == 5) ? c : d;
equilvalent in bash
a=$([ "$b" == 5 ] && echo "$c" || echo "$d")
I tried to use this in my case as follows
env=$1
Config=$([ "$env" == "qa" ]] && echo "${ConfigA[#]}" || echo "${ConfigB[#]}")
However in the above case I get the output
hostname1 hostname2
but Its not an array, since when I try to loop over it, it print both at once.
I have also tried to surround the array within () like
Config=$([ "$env" == "qa" ]] && echo "( ${ConfigA[#]} )" || echo "( ${ConfigB[#]} )")
but that also doesn't help.
How do I assign the array to a new variable with a ternary operator?
I understand I can do it with a if-else condition, but I would like to do it with ternary operator
Thanks for any help
So instead of having () within quotes in the second case, another approach to assign array to a variable like
[ "$env" == "qa" ]] && Config=( "${ConfigA[#]}" ) || Config( "${ConfigB[#]}" )
works
What happened in
Config=$([ "$env" == "qa" ]] && echo "( ${ConfigA[#]} )" || echo "( ${ConfigB[#]} )")
was that echo converted the array to a string and appended the () around it and hence it did not work
There is no simple way to copy array from a variable to another in bash.
According to this Bash: How to assign an associative array to another variable name (e.g. rename the variable)?, a workaround you could use is the following:
[[ "$env" == "qa" ]] && eval $(declare -p ConfigA | sed 's/ConfigA/Config/') || eval $(declare -p ConfigB | sed 's/ConfigB/Config/')
echo ${Config[*]}
hostname3 hostname4

print block of text to file from awk script [banner like]

I have awk script doing some processing and sending it's output to a file.
How would I writeout in BEGIN block of my awk program a banner-like message
to that file first, something like bash heredoc.
I know I could use multiple print commands, but is there some way of having
one print command but preserving multiline text with newlines etc.
So the output should look something like this:
#########################################
# generated by some author #
# ENVIRON["VAR"]
#########################################
Additional problem of nice formatting is that ENVIRON["VAR"] should be
expanded there in a middle of string.
The simple way is to use a heredoc and save it in an awk variable:
VAR="whatever"
awk -v var="\
#########################################
# generated by some author #
# $VAR
#########################################" '
BEGIN{ print var }
'
#########################################
# generated by some author #
# whatever
#########################################
Alternatively, this may be more than you wanted, but below is the command I use to provide something a bit better than just here docs in awk. I find it absolutely invaluable when adding template text to multiple files..
It's a shell script which takes an awk script with slightly extended syntax (to facilitate here documents) as input, invokes gawk to transform that extended syntax to normal awk print statements, and then calls gawk again to execute the resulting script.
I call it "epawk" for "extended print" awk and what follows is the tool plus several examples of how to use it. When you invoke it instead of invoking awk directly you can write scripts that include blocks of pre-formatted text for printing like you'd want to with a here-doc (the space before each # is a tab character):
$ export VAR="whatever"
$ epawk 'BEGIN {
print <<-!
#########################################
# generated by some author #
# "ENVIRON["VAR"]"
#########################################
!
}'
#########################################
# generated by some author #
# whatever
#########################################
It works by creating an awk script from your awk script and then executing it. If you'd just like to see the script that is being generated, epawk will print the generated script instead of executing it if you give it the -X argument, e.g.:
$ epawk -X 'BEGIN {
print <<-!
#########################################
# generated by some author #
# "ENVIRON["VAR"]"
#########################################
!
}'
BEGIN {
print "#########################################"
print "# generated by some author #"
print "# "ENVIRON["VAR"]""
print "#########################################"
}
THE SCRIPT:
$ cat epawk
#!/usr/bin/env bash
# The above must be the first line of this script as bash or zsh is
# required for the shell array reference syntax used in this script.
##########################################################
# Extended Print AWK
#
# Allows printing of pre-formatted blocks of multi-line text in awk scripts.
#
# Before invoking the tool, do the following IN ORDER:
#
# 1) Start each block of pre-formatted text in your script with
# print << TERMINATOR
# on it's own line and end it with
# TERMINATOR
# on it's own line. TERMINATOR can be any sequence of non-blank characters
# you like. Spaces are allowed around the symbols but are not required.
# If << is followed by -, e.g.:
# print <<- TERMINATOR
# then all leading tabs are removed from the block of pre-formatted
# text (just like shell here documents), if it's followed by + instead, e.g.:
# print <<+ TERMINATOR
# then however many leading tabs are common across all non-blank lines
# in the current pre-formatted block are removed.
# If << is followed by =, e.g.
# print <<= TERMINATOR
# then whatever leading white space (tabs or blanks) occurs before the
# "print" command will be removed from all non-blank lines in
# the current pre-formatted block.
# By default no leading spaces are removed. Anything you place after
# the TERMINATOR will be reproduced as-is after every line in the
# post-processed script, so this for example:
# print << HERE |"cat>&2"
# foo
# HERE
# would cause "foo" to be printed to stderr.
#
# 2) Within each block of pre-formatted text only:
# a) Put a backslash character before every backslash (\ -> \\).
# b) Put a backslash character before every double quote (" -> \").
# c) Enclose awk variables in double quotes without leading
# backslashes (awkVar -> "awkVar").
# d) Enclose awk record and field references ($0, $1, $2, etc.)
# in double quotes without leading backslashes ($1 -> "$1").
#
# 3) If the script is specified on the command line instead of via
# "-f script" then replace all single quote characters (') in or out
# of the pre-formatted blocks with their ANSI octal escape sequence (\047)
# or the sequence '\'' (tick backslash tick tick). This is normal and is
# required because command-line awk scripts cannot contain single quote
# characters as those delimit the script. Do not use hex \x27, see
# http://awk.freeshell.org/PrintASingleQuote.
#
# Then just use it like you would gawk with the small caveat that only
# "-W <option>", not "--<option>", is supported for long options so you
# can use "-W re-interval" but not "--re-interval" for example.
#
# To just see the post-processed script and not execute it, call this
# script with the "-X" option.
#
# See the bottom of this file for usage examples.
##########################################################
expand_prints() {
gawk '
!inBlock {
if ( match($0,/^[[:blank:]]*print[[:blank:]]*<</) ) {
# save any blanks before the print in case
# skipType "=" is used.
leadBlanks = $0
sub(/[^[:blank:]].*$/,"",leadBlanks)
$0 = substr($0,RSTART+RLENGTH)
if ( sub(/^[-]/,"") ) { skipType = "-" }
else if ( sub(/^[+]/,"") ) { skipType = "+" }
else if ( sub(/^[=]/,"") ) { skipType = "=" }
else { skipType = "" }
gsub(/(^[[:blank:]]+|[[:blank:]]+$)/,"")
if (/[[:blank:]]/) {
terminator = $0
sub(/[[:blank:]].*/,"",terminator)
postprint = $0
sub(/[^[:blank:]]+[[:blank:]]+/,"",postprint)
}
else {
terminator = $0
postprint = ""
}
startBlock()
next
}
}
inBlock {
stripped=$0
gsub(/(^[[:blank:]]+|[[:blank:]]+$)/,"",stripped)
if ( stripped"" == terminator"" ) {
endBlock()
}
else {
updBlock()
}
next
}
{ print }
function startBlock() { inBlock=1; numLines=0 }
function updBlock() { block[++numLines] = $0 }
function endBlock( i,numSkip,indent) {
if (skipType == "") {
# do not skip any leading tabs
indent = ""
}
else if (skipType == "-") {
# skip all leading tabs
indent = "[\t]+"
}
else if (skipType == "+") {
# skip however many leading tabs are common across
# all non-blank lines in the current pre-formatted block
for (i=1;i<=numLines;i++) {
if (block[i] ~ /[^[:blank:]]/) {
match(block[i],/^[\t]+/)
if ( (numSkip == "") || (numSkip > RLENGTH) ) {
numSkip = RLENGTH
}
}
}
for (i=1;i<=numSkip;i++) {
indent = indent "\t"
}
}
else if (skipType == "=") {
# skip whatever pattern of blanks existed
# before the "print" statement
indent = leadBlanks
}
for (i=1;i<=numLines;i++) {
sub(indent,"",block[i])
print "print \"" block[i] "\"\t" postprint
}
inBlock=0
}
' "$#"
}
unset awkArgs
unset scriptFiles
expandOnly=0
while getopts "v:F:W:f:X" arg
do
case $arg in
f ) scriptFiles+=( "$OPTARG" ) ;;
[vFW] ) awkArgs+=( "-$arg" "$OPTARG" ) ;;
X ) expandOnly=1 ;;
* ) exit 1 ;;
esac
done
shift $(( OPTIND - 1 ))
if [ -z "${scriptFiles[*]}" -a "$#" -gt "0" ]
then
# The script cannot contain literal 's because in cases like this:
# 'BEGIN{ ...abc'def... }'
# the args parsed here (and later again by gawk) would be:
# $1 = BEGIN{ ...abc
# $2 = def... }
# Replace 's with \047 or '\'' if you need them:
# 'BEGIN{ ...abc\047def... }'
# 'BEGIN{ ...abc'\''def... }'
scriptText="$1"
shift
fi
# Remaining symbols in "$#" must be data file names and/or variable
# assignments that do not use the "-v name=value" syntax.
if [ -n "${scriptFiles[*]}" ]
then
if (( expandOnly == 1 ))
then
expand_prints "${scriptFiles[#]}"
else
gawk "${awkArgs[#]}" "$(expand_prints "${scriptFiles[#]}")" "$#"
fi
elif [ -n "$scriptText" ]
then
if (( expandOnly == 1 ))
then
printf '%s\n' "$scriptText" | expand_prints
else
gawk "${awkArgs[#]}" "$(printf '%s\n' "$scriptText" | expand_prints)" "$#"
fi
else
printf '%s: ERROR: no awk script specified.\n' "$toolName" >&2
exit 1
fi
USAGE EXAMPLES:
$ cat data.txt
abc def"ghi
.
#######
$ cat script.awk
{
awkVar="bar"
print "----------------"
print << HERE
backslash: \\
quoted text: \"text\"
single quote as ANSI sequence: \047
literal single quote (ONLY works when script is in a file): '
awk variable: "awkVar"
awk field: "$2"
HERE
print "----------------"
print <<-!
backslash: \\
quoted text: \"text\"
single quote as ANSI sequence: \047
literal single quote (ONLY works when script is in a file): '
awk variable: "awkVar"
awk field: "$2"
!
print "----------------"
print <<+ whatever
backslash: \\
quoted text: \"text\"
single quote as ANSI sequence: \047
literal single quote (ONLY works when script is in a file): '
awk variable: "awkVar"
awk field: "$2"
whatever
print "----------------"
}
.
$ epawk -f script.awk data.txt
----------------
backslash: \
quoted text: "text"
single quote as ANSI sequence: '
literal single quote (ONLY works when script is in a file): '
awk variable: bar
awk field: def"ghi
----------------
backslash: \
quoted text: "text"
single quote as ANSI sequence: '
literal single quote (ONLY works when script is in a file): '
awk variable: bar
awk field: def"ghi
----------------
backslash: \
quoted text: "text"
single quote as ANSI sequence: '
literal single quote (ONLY works when script is in a file): '
awk variable: bar
awk field: def"ghi
----------------
.
$ epawk -F\" '{
print <<!
ANSI-tick-surrounded quote-separated field 2 (will work): \047"$2"\047
!
}' data.txt
ANSI-tick-surrounded quote-separated field 2 (will work): 'ghi'
.
epawk -F\" '{
print <<!
Shell-escaped-tick-surrounded quote-separated field 2 (will work): '\''"$2"'\''
"
}' data.txt
Shell-escaped-tick-surrounded quote-separated field 2 (will work): 'ghi'
.
$ epawk -F\" '{
print <<!
Literal-tick-surrounded quote-separated field 2 (will not work): '"$2"'
!
}' data.txt
Literal-tick-surrounded quote-separated field 2 (will not work):
.
$ epawk -X 'BEGIN{
print <<!
foo
bar
!
}'
BEGIN{
print " foo"
print " bar"
}
.
$ cat file
a
b
c
.
$ epawk '{
print <<+! |"cat>o2"
numLines="NR"
numFields="NF", $0="$0", $1="$1"
!
}' file
.
$ cat o2
numLines=1
numFields=1, $0=a, $1=a
numLines=2
numFields=1, $0=b, $1=b
numLines=3
numFields=1, $0=c, $1=c
.
$ epawk 'BEGIN{
cmd = "sort"
print <<+! |& cmd
d
b
a
c
!
close(cmd, "to")
while ( (cmd |& getline line) > 0 ) {
print "got:", line
}
close(cmd)
}' file
got: a
got: b
got: c
got: d
$ cat a.awk
BEGIN {
print "\
#########################################\n\
# generated by some author #\n\
#########################################"
}
$ awk -f a.awk
#########################################
# generated by some author #
#########################################
Is this some that you look for?
var="Peter Hanson"
awk -v auth="$var" '
BEGIN {print "#########################################"
print "# generated by some author #"
printf "#";
l=int((41-length(auth))/2)
r=((41-length(auth))/2-l)*2
for (i=1;i<=l;i++)
printf " "
printf "%s",auth
for (i=1;i<=l+r-2;i++)
printf " "
print "#"
print "#########################################"
}' file
#########################################
# generated by some author #
# Peter Hanson #
#########################################
This will take the data in the variable var and print it as the second line.
It does adjust the field with, so it its centered.
You need to enter your code for the rest after the last print

Resources