Ignacio,
In order to accomplish what you want, I just add an 'else' statement into
the script without having to change the test condition. The awk command
becomes:
awk '/Execute/ {line1 = $0
getline
if ($0 ~ /^ /) {print line1, $0}
else {print line1}
}' ${DISP}.output > ${DISP}.cmd
But, alas, this simple tweak would miss every other single-line Execute
action if they're listed consecutively (because of the getline command).
Getting around this problem is more difficult than it seems due to the
this-line-next-line pattern matching required. So I take the easy way out
by counting fields in each line and modify the awk scriptlet to this:
awk '/Execute/ && NF > 5 {print $0}
/Execute/ && NF <= 5 {line1 = $0; getline
if ($0 ~ /^ =/) {print line1, $0}
}' ${DISP}.output > ${DISP}.cmd
This should work for you now.
Duc
On Wed, Apr 19, 2017 at 9:44 AM, QUEIROLO, IGNACIO ESTEBAN <
ignacio.queirolo@xxxxxxx> wrote:
Thanks Duc!
Looking at a sample the d_edit output I could observe that sometimes there
are lines with the word "Execute" occupying only one line. To improve the
logic, I would check the first field in the current line to see if it is
numeric and if so, I would check if the next first field in the next line
is also numeric, and if the two of them are numeric, I would print the
current line, if not, concatenate both and then skip two lines. If the
first field in the current line is not numeric, I would print the current
line and continues with the next.
I have no idea how to do this so If you have some tips to accomplish this,
they are very welcome. What I do know is to check if the field is numeric
with the following sentence:
awk '$1 ~ /^[0-9]+$/ {print $0}' <file>
Thanks again!
Ignacio
-----Mensaje original-----
De: foxboro-bounce@xxxxxxxxxxxxx [mailto:foxboro-bounce@xxxxxxxxxxxxx] En
nombre de Duc M Do
Enviado el: miércoles, 12 de abril de 2017 02:40 p.m.
Para: foxboro@xxxxxxxxxxxxx
Asunto: Re: [foxboro] Parsing dedit output
Ignacio,
Greg is right. A simple awk scriptlet can do what you need. The ââ¬â¹key is
how to tell awk programmatically to concatenate the 2 lines where you want
them concatenated, and not do it where you don't.
Looking at a sample d_edit output, I can see the lines you want to join
are in the Operator Actions section, and all have the "Execute" action in
them.
So then it's a simple matter of searching for lines that have "Execute",
looking at the next line to see if it starts with a bunch of spaces (4 to
be exact), if so, join the two lines.
Here's your script:
========= begin of script =========
#!/bin/sh
# this file is concat.sh
# Usage: concat.sh <dispname>
# the output is saved in <dispname>.cmd
DEDIT=/usr/fox/wp/bin/tools/d_edit
DISP=$1
$DEDIT -l $DISP > ${DISP}.output
awk '/Execute/ {line1 = $0
getline
if ($0 ~ /^ /) {print line1, $0}
}' ${DISP}.output > ${DISP}.cmd rm ${DISP}.output =========
end of script =========
I leave it as an exercise for you to remove the extra spaces at the end of
the first line.
Good luck!
Duc