Reputation: 333
How can I write this program? C Shell is maybe approprite, however, it doesn't matter anything else.
The program read an input file with two columns of numbers and it gives output program with these two origin columns and add three columns of numbers. In each added column will be the same number (in the third column 1.000, in the forth 1 and in the fifth 6). Between columns will be define count of spaces: 1st column 3 spaces 2nd column 5 spaces 3rd column 5 spaces 4th column 4 spaces 5th column.
Thank you very much for your help.
Input:
56603.6153 2.2126
56603.6156 2.2156
56603.6158 2.2108
56603.6161 2.2161
56603.6163 2.2012
56603.6166 2.2049
56603.6168 2.1952
56603.6171 2.2195
56603.6173 2.2107
56603.6176 2.1998
56603.6178 2.2163
56603.6180 2.2240
56603.6183 2.2185
56603.6185 2.2216
56603.6188 2.2266
56603.6190 2.2106
56603.6193 2.2007
56603.6195 2.2202
56603.6198 2.2277
56603.6203 2.2119
56603.6205 2.1995
56603.6208 2.1996
56603.6210 2.2134
56603.6213 2.2238
56603.6217 2.2016
56603.6220 2.2012
56603.6222 2.2125
56603.6225 2.2124
56603.6227 2.2064
Output
56603.6153 2.6326 1.000 1 6
56603.6156 2.6356 1.000 1 6
56603.6158 2.6308 1.000 1 6
56603.6161 2.6361 1.000 1 6
56603.6163 2.6212 1.000 1 6
56603.6166 2.6249 1.000 1 6
56603.6168 2.6152 1.000 1 6
56603.6171 2.6395 1.000 1 6
56603.6173 2.6307 1.000 1 6
56603.6176 2.6198 1.000 1 6
56603.6178 2.6363 1.000 1 6
56603.6180 2.6440 1.000 1 6
56603.6183 2.6385 1.000 1 6
56603.6185 2.6416 1.000 1 6
56603.6188 2.6466 1.000 1 6
56603.6190 2.6306 1.000 1 6
56603.6193 2.6207 1.000 1 6
56603.6195 2.6402 1.000 1 6
56603.6198 2.6477 1.000 1 6
56603.6203 2.6319 1.000 1 6
56603.6205 2.6195 1.000 1 6
56603.6208 2.6196 1.000 1 6
56603.6210 2.6334 1.000 1 6
56603.6213 2.6438 1.000 1 6
56603.6217 2.6216 1.000 1 6
56603.6220 2.6212 1.000 1 6
56603.6222 2.6325 1.000 1 6
56603.6225 2.6324 1.000 1 6
56603.6227 2.6264 1.000 1 6
56603.6230 2.6292 1.000 1 6
56603.6232 2.6294 1.000 1 6
Upvotes: 0
Views: 45
Reputation: 37404
Using awk for it. Here setting static space between the columns:
$ awk '{print $1 " " $2 " 1.000 1 6"}' file
56603.6153 2.2126 1.000 1 6
56603.6156 2.2156 1.000 1 6
56603.6158 2.2108 1.000 1 6
...
You could also use printf
and its modifiers to reserve space for columns. Here we reserve 9 spaces right-justified for the second column which for 6 character column would leave required 3 characters between the columns but:
$ awk '{printf "%s%9s\n", $1, $2}' file
56603.6158 2.2108
56603.6161 2.2161
56603.6163 20.2012
|---9---|
Reserving space for the first column left-justified:
$ awk '{printf "%-13s%s\n", $1, $2}' file
56603.6153 2.2126
56603.6161 2.2161
56603.6163 20.2012
|----13-----|
And so on:
$ awk '{printf "%-13s%-11s%s\n", $1, $2, 1000}' file
56603.6153 2.2126 1000
56603.6156 2.2156 1000
56603.6163 20.2012 1000
|----13-----||---11----|
and:
$ awk '{printf "%-13s%-11s%-9s%-5s%s\n", $1, $2, 1000, 6, 1}' file
56603.6153 2.2126 1000 6 1
56603.6161 2.2161 1000 6 1
56603.6163 20.2012 1000 6 1
Upvotes: 1