Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

bash - Format output in columns

I was wondering how to format the following output:

-0.3116274D-04
-0.2389361D-04
-0.1192458D-04
0.3306203D-04
0.2534987D-04
0.1265136D-04
-0.2167920D-04
-0.3713258D-04
-0.2294900D-05
-0.4151710D-05
-0.7674479D-03
-0.5749288D-04
0.1393479D-04
0.6763913D-04
0.2515100D-05
-0.3638000D-06
-0.2630000D-06
-0.2445230D-06
0.1534680D-05
0.1579750D-04
0.2922010D-04
0.5390530D-04
0.8701990D-04
0.1132741D-03
0.9665700D-04
0.3337340D-04
-0.4121240D-05

into five columns, by transposing first:

-0.3116274D-04  -0.2389361D-04  -0.1192458D-04   0.3306203D-04   0.2534987D-04
 0.1265136D-04  -0.2167920D-04  -0.3713258D-04  -0.2294900D-05  -0.4151710D-05
-0.7674479D-03  -0.5749288D-04   0.1393479D-04   0.6763913D-04   0.2515100D-05
-0.3638000D-06  -0.2630000D-06  -0.2445230D-06   0.1534680D-05   0.1579750D-04
 0.2922010D-04   0.5390530D-04   0.8701990D-04   0.1132741D-03   0.9665700D-04
 0.3337340D-04  -0.4121240D-05          

My first approach was:

sed 's/
//g' File | column -n
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try this:

printf "%14s  %14s  %14s  %14s  %14s
" $(cat data.txt)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...