С GNU awk для FIELDWIDTHS
и 4-м аргументом split()
:
$ cat tst.awk
BEGIN { OFS="," }
FNR==1 {
n = split($0,flds," ",seps)
for (i=1; i<n; i++) {
FIELDWIDTHS = FIELDWIDTHS length(flds[i] seps[i]) " "
}
FIELDWIDTHS = FIELDWIDTHS "*"
$0 = $0
}
$1 ~ /^[[:space:]]*$/ {
f[NF] = f[NF] " " $NF
next
}
NR > 1 { prt() }
{
for (i=1; i<=NF; i++) {
f[i] = $i
}
}
END { prt() }
function prt() {
for (i=1; i<=NF; i++) {
if (i != 2) {
gsub(/[[:space:]]+/," ",f[i])
gsub(/^ | $/,"",f[i])
gsub(/"/,"\"\"",f[i])
printf "\"%s\"%s", f[i], (i<NF ? OFS : ORS)
}
}
}
с новым вводом сэмпла:
$ awk -f tst.awk file
"Name","Type","Visible","Description"
"a","integer","false","Oh, I kept the first for another day!"
"b","float","true","I took the one less traveled by"
"c","integer","false","Two roads diverged in a yellow wood, And sorry I could not travel both And be one traveler, long I stood"
"d","float","false","And that has made all the difference."
и с вводом исходного сэмпла:
$ awk -f tst.awk file
"Name","Type","Visible","Description"
"place.targetPinCongForV8","integer","false","Target pin congestion for V8"
"place.slrUtilDelta","float","false","target SLR utilization increase from design utilization"
"place.targLHBSlack","integer","false","Target Budget Slack Violation for LH Partitioning."
"place.slrTargetUtil4Discrete","float","false","SLR target utilization"
"place.supportHDPlatformClocking","boolean","false","param to consider clocking for HD Partition flow same as PR flow"
"place.targetLHPartitionCost","float","false","Target LH based Partition Cost."
"place.sweepClockRootsPostPlacement","boolean","false","param to turn on clock root sweep at the end of placement"
"place.startupe3InSlave","boolean","false","check if startupe3 has connections on selected pins and LOC in slave SLR and send out error"
"place.softShapeFlow","boolean","false","Test soft shape flow"
"place.spiralModeClockRootSweep","boolean","false","param to start a spiral search to find best clock roots"
"place.superLongSimpl","boolean","false","spread SLLs in SIMPL"
"place.superLongSimplThreshold","float","false","min util to do super long spreading in SIMPL"
"place.superLongMatcher","boolean","false","use bipart matching to legalize super longs"
"place.superLongMatcherAnchor","boolean","false","use bipart matching to legalize super longs"
"place.swapSuperLong","boolean","false","turn on/off swapping of super longs"
"place.sweepClockRootsBeforePostCommitOpt","boolean","false","param to turn on clock root sweep in before starting Post Commit Optmization"
"place.sparseSliceMaker","boolean","false","At the end of post commit opt try to space out lut/ff bels within each SLICE, if possible"
"place.supportMultiRootClockRouting","boolean","false","Turn on support for template multi-root clock routing"
"place.sweepClockRootsBeforeDPPathOptim","boolean","false","param to turn on clock root sweep in before starting DP Path OPtimizer"
"place.splitCrossingNetsMode","string","false","Specifies when to split SLR crossing nets by dummy blocks. The value can be : empty string which means do not split nets 'GP' which means split nets in global placer and keep them split for remaining part of placer 'DP' which means split nets in detail placer and keep them split for remaining part of placer any combination of 'BigShape', 'SmallShape' and 'FF' which means split nets to specified detail placement step and restore nets after that step is done"
"place.slrTargetUtil4PR","float","false","SLR target utilization"
"place.startSliceAreaCoef","float","false","Initial Slice Area Coef."
"place.smallerBloatPrefCost","float","false","minimum ratio of new bloat cost to older minimum cost needed to choose a larger bloat value"
"place.smearFactorRelaxCoef","float","false","Relax BB smearing coeficient"
"place.smallShapeLegBinAspectRatio","float","false","The aspect ratio of the bins in small shape legalization"
"place.synthPlaceFlow","boolean","false","Placer inside synthesis flow"