Quantcast
Channel: Active questions tagged bash+awk - Ask Ubuntu
Viewing all articles
Browse latest Browse all 102

How to rearrange text file via awk?

$
0
0

I wanna print field (from 4th to the last field) as new line for each by inserting increasing arithmetically variable (from 5 to 25) after 3rd field in the text file.

Data format:

01.01.1995 01:00 1.0 1.2 2.5 3 4.8 5.231.01.1995 23.00 31.0 2.3 7.5 8.7 8.7 10

.

awk '{for(i=5;i<=25;i+=5) print $1,$2,$3,i,$(3+i/5)}'

Desired output:

01.01.1995 01.00 1.0 5 1.201.01.1995 01.00 1.0 10 2.501.01.1995 01.00 1.0 15 301.01.1995 01.00 1.0 20 4.801.01.1995 01.00 1.0 25 5.231.01.1995 23.00 31.0 5 2.331.01.1995 23.00 31.0 10 7.531.01.1995 23.00 31.0 15 8.731.01.1995 23.00 31.0 20 8.731.01.1995 23.00 31.0 25 10

Desired output 2:

01.01.1995 01.00 1.0 5 5.201.01.1995 01.00 1.0 10 4.801.01.1995 01.00 1.0 15 301.01.1995 01.00 1.0 20 2.501.01.1995 01.00 1.0 25 1.231.01.1995 23.00 31.0 5 1031.01.1995 23.00 31.0 10 8.731.01.1995 23.00 31.0 15 8.731.01.1995 23.00 31.0 20 7.531.01.1995 23.00 31.0 25 2.3

So the first three field should be same.


Viewing all articles
Browse latest Browse all 102

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>