I would like redirect output to files using shell programming
I have a huge database of students, I would like extract these data and write to individual file for each students.
I am running a loop in shell program (.sh file), the output of each run in the loop need to redirected to a file with variable name. I tried the following line, but it did not work, where BodyMsg is the data and Rollno is the students roll number. echo $BodyMsg > $RolNo".html" |
Try echo "$BodyMsg" > "$RolNo.html"
|
If you are executing a loop, you may be writing in multiple steps within the loop. Note that the notation for the first write will probably need to be different from the subsequent writes:
Code:
echo "$data1" > "$studentFile"
|
Note that you can redirect standard output to a file permanently using
Code:
exec >> file-to-append-to In your case, you can do e.g. Code:
#!/bin/sh |
thanks all... it is solved now...
|
Mark the thread as solved.
|
All times are GMT -5. The time now is 08:42 AM. |