I am trying to:
- Always add
0 0 0
to the first row of the file. - Multiply
2*pi
or6.2832
to the first column of a three-column file formatted similar below, but only if the line begins with a numeral. The second and third columns are retained as is. - Append a
*
on the start of the line if it does not start with a numeral, except if it already is a*
. i.e. just comment out the current row, except if it is already commented out.
This is a sample input file:
* radius, section, index
1.12 A 0
2.0 A 1
* There is white space before this comment
* This is a comment indicating a new section
5 B 0
3.17 B 1
7.3 B 7
This row starts with an alphabet char and should be commented out by the script.
0 C 1
1 C 2
And here is the intended output:
0 0 0
* radius, section, index
7.037184 A 0
12.5664 A 1
* There is white space before this comment
* This is a comment indicating a new section
31.416 B 0
19.917744 B 1
45.86736 B 7
* This row starts with an alphabet char and should be commented out by the script.
0 C 1
6.2832 C 2
What I've done so far:
for tempfile in *.txt; do
echo '0 0 0' > temp
cat $tempfile >> temp
awk '{$1*=6.2832}{print}' temp > $tempfile
#awk '/^(0-9)/{$1*=6.2832}{print}' temp > $tempfile
rm temp
done
But what this script does to the sample use-case above:
0 0 0
0 radius, section, index
7.03718 A 0
12.5664 A 1
0 There is white space before this comment
0 This is a comment indicating a new section
31.416 B 0
19.9177 B 1
45.8674 B 7
0 row starts with an alphabet char and should be commented out by the script.
0 C 1
6.2832 C 2
PS. The Linux box is off-grid and does not have mlr
.
I also do not have root/admin credentials.
Really appreciate any help from the community. Thanks in advance,
C