Copy a number from a text file to another in a script.
Hi,
I'm a new Linux user and I need your help. The output of a CFD code is the following inout file: Code:
inlet section: Code:
set title "PAKD-A" |
what have you tried and where are you stuck.
it seems like grep/awk/sed/cut/paste/... is what you are after. |
Since today I've done it manually copying and pasting the number between the two files using vi. But I have to do it very often so I'd like to find a way to do it automatically in the script I use to run the code. I'm working on my master's degree thesis in mechanical engineering and it's the first time I use linux; in the past I've only used MATLAB code so I'm not used to working with text files. Looking for a solution on the net I've found this forum.
|
Quote:
Your original post contains an inlet section and an outlet section. Are these two distinct files or simply text headers in a single input file? How many files are you talking about, including the desired output file? Is this problem a simple matter of copying the input file to the output file except deleting one specific line, and in place of that line a copy of everything in a second input file? It might help if you give names to each of these files and show each in a different "code box." Any section of text in your post may be shown in a "code box" by highlighting it and then clicking on the pound sign (a/k/a hash mark) icon. Daniel B. Martin |
As Daniel B. Martin suggested I put the two files in 'code boxes'. The first and bigger one is the inout file, while the second one is the Plot file (needed to plot the results with gnuplot).
Using the command: Code:
grep -w "p aver." inout >temp Code:
p aver. = 0.920042 dim.= 100.954803 [kPa] Code:
pr=0.920042 |
quick-and-dirty:
Code:
#man awk sed |
Thank you very much schneidz, your code is really brief but effective!!!
I finally managed to do it on my own with this code: Code:
# |
a part could be (untested!):
Code:
set - $(grep '^ p aver\.' "$infile") |
Also your second alternative works.
Thank you so much again!! Lorenzo |
Several correct solutions have already been posted.
OP, you may tighten your code by using >> which means "append to existing file." That eliminates the need for temporary files. With InFile1 ... Code:
Once upon a midnight dreary, while I pondered weak and weary, Code:
Inserted text, line 1 the entire InFile2 with this sequence ... Code:
sed -n '1,/While I nodded/p' $InFile1 |sed '$d' >$OutFile Code:
Once upon a midnight dreary, while I pondered weak and weary, |
All times are GMT -5. The time now is 03:21 AM. |