Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

copy lines whilst adding an incremental column

Status
Not open for further replies.

vidmo

Technical User
Sep 18, 2006
14
GB
Hi,

I have a file like this:

.....
10801 0.0 14.1 1.09083 0.00744552 0.00142242 0.0201911
10802 0.10 14.08 1.06125 0.00697322 0.00133229 0.0201911
10803....

$1 is an length coordinate, and I would like to create a depth coordinate as $2 so that i have a depth every 10 cm for 1 metre and then every metre for 10 metres for each length, keeping the rest of the data on the other columns (differs between coordinates):

....
10801 8 0.0 14.1 1.09083 0.00744552 0.00142242 0.0201911
10801 9 0.0 14.1 1.09083 0.00744552 0.00142242 0.0201911
10801 10 0.0 14.1 1.09083 0.00744552 0.00142242 0.0201911
10802 0.1 0.10 14.08 1.06125 0.00697322 0.00133229 0.0201911
10802 0.2 0.10 14.08 1.06125 0.00697322 0.00133229 0.0201911
10802 0.3 0.10 14.08 1.06125 0.00697322 0.00133229 0.0201911
10802 0.4 0.10 14.08 1.06125 0.00697322 0.00133229 0.0201911
10802 0.5 0.10 14.08 1.06125 0.00697322 0.00133229 0.0201911
10802 0.6 0.10 14.08 1.06125 0.00697322 0.00133229 0.0201911
10802 0.7 0.10 14.08 1.06125 0.00697322 0.00133229 0.0201911
10802 0.8 0.10 14.08 1.06125 0.00697322 0.00133229 0.0201911
10802 0.9 0.10 14.08 1.06125 0.00697322 0.00133229 0.0201911
10802 1 0.10 14.08 1.06125 0.00697322 0.00133229 0.0201911
10802 2 0.10 14.08 1.06125 0.00697322 0.00133229 0.0201911
....

I think that I need an array, but am completely unsure on how to proceed,

I would greatly appreciate any help!

thank you very much in advance- even solving for every metre would be helpful,

Vid
 
a solution:
for i in 0.1 0.2 0.3 0.4 0.5 0.6 0.8 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0
do
awk '{print $1, '"$i"', $2, $3, $4, $5, $6, $7, $8}' ${file}temp3.txt > s${file}$i.txt
done
cat s${file}*.txt | sort > ${file}_fin.txt

thanks anyway
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top