Operating System - HP-UX
1753325 Members
4776 Online
108792 Solutions
New Discussion юеВ

Re: format to output files ...

 
SOLVED
Go to solution
Manuales
Super Advisor

format to output files ...

hi
i ran a script and the output file has this

this is the line to get below information
echo $a $b $c

a_bcd_ea_e_ai_aa_aa 60 VALORES2
i_sdf_sdf_ 30 JUSTO
t_SF 20 CASA
jkjkkjkkjkkkjk 80 ARBOLES

i want the output as follows:
a_bcd_ea_e_ai_aa_aa 60 VALORES2
i_sdf_sdf_ 30 JUSTO
t_SF 20 CASA
jkjkkjkkjkkkjk 80 ARBOLES

i know a command called awk, but i do not know how to use it to get abowe format.

please your help.
Thanks.
3 REPLIES 3
Manuales
Super Advisor

Re: format to output files ...



i want the output as follows:

xxxxxx xxxxxx xxxxxx
xxxxxx xxxxxx xxxxxx
xxxxxx xxxxxx xxxxxx
xxxxxx xxxxxx xxxxxx
xxxxxx xxxxxx xxxxxx

i mean, columns ordered.
thanks.



Dennis Handly
Acclaimed Contributor
Solution

Re: format to output files ...

>want the output as follows:

Then you want to use printf, either the command or within awk.

This right justifies:
printf "%20s %5s %10s\n" "$a" "$b" "$c"

This left justifies $a and $c:
printf "%-20s %5s %-10s\n" "$a" "$b" "$c"

James R. Ferguson
Acclaimed Contributor

Re: format to output files ...

Hi Manuales:

In keeping with "best practices", have a look at the 'printf(1)' manpages:

http://bizsupport.austin.hp.com/bc/docs/support/SupportManual/c02264041/c02264041.pdf

The 'printf' function can be used in shells, with 'awk' and with 'perl'.

# printf "%-8s%-8s%-8s\n" a b c

# echo "a b c"|awk '{printf "%-8s%-8s%-8s\n",$1,$2,$3}'

# perl -e 'printf "%-8s%-8s%-8s\n","a","b","c"'

Notice that in the shell example, no comma delimiters are used to separate the arguments to 'printf'.

Regards!

...JRF...