2
I have a certain folder with several files, and these in turn contain inside description of coordinates points cartesian X and Y.
However, I want to replace these points automatically and dynamically, that is, use while
to run all these files running the sed
to change the X and Y values of the files.
Well, what becomes the crucial point here, is to make the insertion coming from a printer/counter until end all the files contained in the folder.
The detail is that for every 5(five) files the Y must receive identical values, and the next 5 files, a new number is put by a jump of 0 - 5. See the example:
list of first 5 files:
X: 100 Y: 0
X: 200 Y: 0
X: 300 Y: 0
X: 400 Y: 0
X: 500 Y: 0
list of the next 5 files:
X: 600 Y: 5
X: 700 Y: 5
X: 800 Y: 5
X: 900 Y: 5
X: 1000 Y: 5
list of the following 5 files:
X: 1100 Y: 10
X: 1200 Y: 10
X: 1300 Y: 10
X: 1400 Y: 10
X: 1500 Y: 10
I think I got the logic right! The dots are being added by integer numbers to a counter, which puts them in the measure of an input of 5 files at a time, starting with the number 100 for the X axis, and right after the second X of the second file for 200, and for the third file 300, in the fourth X 400 file and the fifth X 500 file.
Continue calculating/summing from 100 to 100 and adding in the next 5 files, and so it is done for every 5 file cycles. This is for the X axis, ja for the Y axis, it would be almost the same, however we have to take into account the value is lower, being of 5 in 5 considering that should set the same value for the first 5 files and make again the sum for the next 5 files and etc...
Example
#!/bin/sh
X=100;
Y=0;
while [ $Y -lt 5 ]; do
echo -e "X: $X\r";
echo -e "Y: $Y\n";
let X=$X+1;
let Y=$Y+1;
done
Follow the result after running the script
Mathematics is easy to do with shell, but I must admit that I was somewhat lost with the structuring and distribution of the files. Can you show an example of before and after? With the names of the desired files and such?
– Jefferson Quesado
@Jeffersonquesado You may want to assemble this structure to get an idea on your own operating system that is using either MAC or LINUX. Do
$ mkdir teste
, and then create some blank files with the following command:$ for ARQ in {0..15}; do touch teste/$ARQ; done
, then you will only have the job of opening them and adding the coordinates X 0 and Y 0 for everyone else, it will be the same. Now that I need it is elaboration of the script where you should add and increase and replace these zero(s).– Diego Henrique