1753912 Members
8338 Online
108810 Solutions
New Discussion юеВ

awk report help

 
SOLVED
Go to solution
Junior C.
Frequent Advisor

awk report help

All,
I'm trying to print a report from a text file using awk. Following is an example of my current output.

Application1: Application2: Application3:
tes1 test2 test3
test1 test2 test3
test2 test3
test2 test3

Following is the output I would like to have.

Application1: Application2: Application3:
tes1 test2 test3
test1 test2 test3
test2 test3
test2 test3

I appreciate all help.

Thanks,

JC

7 REPLIES 7
James R. Ferguson
Acclaimed Contributor

Re: awk report help

Hi JC:

So where's the *input*? You current output looks like the desired output, too!

Regards!

...JRF...
Junior C.
Frequent Advisor

Re: awk report help

...JFR...

The format did not display correctly.

Output I'm looking for excluding the (.....)

Apps1: Apps2: Apps3:
test1 test2 test3
test1 test2 test3
.......test2 test3
.......test2 test3
.......test2 test3
.............test3
.............test3



Thanks,

JC
James R. Ferguson
Acclaimed Contributor

Re: awk report help

Hi (again) JC:

You still haven't provided the *input*. A sample or attachment is needed.

Regards!

...JRF...
Dennis Handly
Acclaimed Contributor

Re: awk report help

>The format did not display correctly.

Yes, leading and multiple blanks are stripped unless you check the "Retain format" box.
You still may have to attach some files.

>Output I'm looking for excluding the (.....)

You want to indent your output?
Junior C.
Frequent Advisor

Re: awk report help

...JRF...

Attach txt file have the output format I'm looking for.

Each column is a separate file that I combine and want to generate one report.

Thanks,


JC
James R. Ferguson
Acclaimed Contributor
Solution

Re: awk report help

Hi JC:

> Each column is a separate file that I combine and want to generate one report

It appears that a simple 'paste' will accomodate your neeeds:

# paste -d" " file1 file2 file3

...or if you like well-formatted output:

# pr -t -m file1 file2 file3

Regards!

...JRF...
Peter Nikitka
Honored Contributor

Re: awk report help

Hi,

my solution assumes
- the first line of input is a header line, which defines the total number of columns and the width of its columns
- columns may be of differnt sizes
- if the number of fields in a column is less than the header line defines, they get filled from column 1 on.
- I use a dot as filler, to get a better readable output here - just change
gsub(".",".",filler[i])
to
gsub("."," ",filler[i]) to get spaces.
as well as
...=out[num-NF+i]"."
to
...=out[num-NF+i]" "


awk 'NR==1 {for(i=1;i<=NF;i++) {filler[i]=$i;gsub(".",".",filler[i])}
num=NF; print; next}
{if(! NF) {print;next}
for (i=NF;i>0;i--) {out[num-NF+i]=$i; for(k=length(filler[i])-length($i);k;k--)out[num-NF+i]=out[num-NF+i]". "}
for(j=1;j<=num-NF;j++) out[j]=filler[j]; for(i=1;i
of
cat your-infile
Application1: Applicati2: Applica3:
test1 test2 test3
test1 test2 test3
test2 test3
test2 test3
test3

leads to
Application1: Applicati2: Applica3:
test1........ test2...... test3....
test1........ test2...... test3....
............. test2...... test3....
............. test2...... test3....
............. ........... test3....


mfG Peter

The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"