linux - Remove last line from variable string inside the awk script -



linux - Remove last line from variable string inside the awk script -

i made next script:

awk ' { if ($1 ~ /^d/) { a=a $0; } .... -> rest code if (p == 1) { b=a; print b; } } ' input.txt a - store found result, work later can't alter construction b - store part of a, header

input file:

d1file text edont show d2file d3file need remove

a content @ end:

d1file text d2file d3file need remove

what do:

if $1 starts d store within a variable. later move a b , remove lastly line b, output of b should be:

d1file text d2file

i looking solution no luck @ all. thinking store a content array , loop using index-1 remove lastly line, couldn't worked.

is there way that?

awk ' /^d/ { = $0 "\n"} # accumulate lines starting d end { sub(/\n[^\n]*\n$/, "", a); # remove lastly line print } ' input.txt

linux bash awk

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -