- #1
member 428835
Hi PF!
I'm a new Linux user (please be patient :) ). I would like to read data stored as a .dat file from a different directory so I can reference it; do you know how?
Specifically, I want to replace a line from different C files (controlDict and U), located here ./system/controlDict and here ./0/U (lines 33 and 26 respectively).
I also want to access two different .dat files from a directory here /home/josh/Documents/NASA/PSI_DATA/Double_Drain/ICF1-9 where the file names are VEL.dat and VEL_t.dat. VEL.dat is an ## n \times 1## column vector and VEL_t is a single scalar number.
Through a TON of effort, below is what I have.
I've tried googling this solution, but I really have no clue what I'm looking for since I'm so new at bash scripting. Honestly, just getting here was a miracle.
I'm a new Linux user (please be patient :) ). I would like to read data stored as a .dat file from a different directory so I can reference it; do you know how?
Specifically, I want to replace a line from different C files (controlDict and U), located here ./system/controlDict and here ./0/U (lines 33 and 26 respectively).
I also want to access two different .dat files from a directory here /home/josh/Documents/NASA/PSI_DATA/Double_Drain/ICF1-9 where the file names are VEL.dat and VEL_t.dat. VEL.dat is an ## n \times 1## column vector and VEL_t is a single scalar number.
Through a TON of effort, below is what I have.
Code:
# LOOP THROUGH ALL OF VEL
for (( j = 0; j < ${#VEL[@]}; j++ )); # THIS SHOULD LOOP THROUGH ALL OF VEL, THAT IS, ${#VEL[@]} IS THE LENGTH OF VEL, RIGHT?
do
# SET LINE NUMBERS
lineU = 33
lineContDict = 26
# REPLACE lineU (line 33) in ./0/U WITH value uniform (0 $VEL(j) 0)
sed -i "${lineU}s/.*/value uniform (0 ${VEL[j]} 0);/" ./0/U # THIS SHOULD REPLACE ALL OF LINE 33 WITH: value uniform (0 ${VEL[j]} 0); WHERE j IS THE jTH COMPONENT OF VEL
# UPDATE endTime (line 26) IN ./system/controlDict WITH VEL_t
sed -i "${lineContDict}s/.*/endTime j*$VEL_t;/" ./system/controlDict # THIS SHOULD REPLACE LINE 26 WITH: endtime j*VEL_t; WHICH IS j MULTIPLIED BY VEL_t
done
I've tried googling this solution, but I really have no clue what I'm looking for since I'm so new at bash scripting. Honestly, just getting here was a miracle.
Last edited by a moderator: