Maybe if you post some more details we could find a way to help you better. Right now, you're working on two adjacent lines, each pair 10 lines apart. Must be a tribute to your simulation output? The nomenclature used doesn't help either.
A (reduced set of) sample data might help to interpret/find out what you really need...
First of all thanks for your help guys, sorry for my brief absence I had moved on from this to work on something else (also for my thesis).
Good news: the sprintf() did exactly what I needed it to do !
So my problem is solved.
For the sake of completeness though I'll try to again explain my problem, how it was solved and I'll attach some data as a sample although it's quite messy (hence the awk processing) but it might be usefull.
Context:
I'm getting about 20 000+ lines per output file, every 11 lines is 'one set of data'.
The simulation works in timesteps, where every X seconds (10-7 seconds in my case) it will calculate what the particles should do next, output data and then repeat the process on the next timestep.
This awk script only needs a few fields, namely $1,$5 and $6 and only every 11th line and every line before that.
The output is generated by LAMMPS an open source modeling software package, in this case I'm using it to perform a granular simulation of two identical particles colliding with each other.
(from here on out, my translation from Dutch to English might be lacking in certain scientific terms but I'll try to make it as clear as possible so bear with me)
In order to perform parametric studies (or scoping studies) I'm comparing how long it takes for the particles to reach a constant energy (this means the collision is over) and how much energy is left.
On top of that I want to determine the distance the particles overlap during the collision simulation and at what point they reach max overlap.
So back to awk.
Each particle's properties are outputted on a separate line.
This required me to compare values from one set of 11 lines to the next, that's what the if(NR%11==0) is for, so every 11th line is being compared to the next and also every line before the 11th to the next, hence the if( (NR +1)%11==0).
When constant energy has been reached I use the exit command to avoid unnecessary computing (in this case it's barely milliseconds that I save in computing time but i'll soon be up-scaling this to simulations that take days to run).
Here comes the problem.
Initially I stored the NFR value of the maximum overlap point in a variable simply like so:
Further along the input file when constant energy was reached, I printed this variable along with the others I had calculated but it turned out to have changed.
That is to say, when I used the printf() to print 'overlapPoint' it printed the current value of NFR, in other words it reevaluated the 'overlapPoint' variable before printing it.
Using:
however, awk did not reevaluate the 'overlapPoint' variable, since the reference to the internal NFR variable is apparently lost thanks to the sprintf() command.
Which solved the problem for me
If anyone has any suggestions to make my title clearer I'll gladly edit it if I can.
I'm not sure I understand what you are striving for, plus there are some inconsistencies in your spec (NFR variable? change variable?) Howsoever, looking at your sample file, I see it has the time step in each record, and also an indicator for the data you nedd. I tried to simplify your code snippet and came up with this:
which is pretty similar to what your code yields (except for the TIMESTEP which is one less as it starts with 0). Please make sure the DOS line terminators (<CR>, 0x0D) are removed from the file before you try it.
Hi I have a text file with 2 values and I am trying to assign each value to a variable and then write those to text files.
So if the textfile is data.txt with 2 values x and y
I want to assign mean=x, and stdev=y and then write these out in text files alongwith the id ($id has already been... (6 Replies)
hi,
i'm creating a little menu for some users.
i'm running the command:
du -a /apps | sort -n -r | head -n 10 | nl
i then get the top 10 files by size in the /apps directory
the output is like this:
1 101415752 /apps
2 89188064 /apps/userA
3 74521335 ... (1 Reply)
I have a script whose contents are as below
result= awk 's=100 END {print s }'
echo "The result is" $result
The desired output is
The result is 100
My script is running without exiting and i am also not getting the desired output.
Please help (5 Replies)
I am trying to assign a value to a variable thru awk and I am having a lot of problem with it. Pls see the code snippet. The one in RED is the actual code. Other lines are the op created by the system. As you can see from the data, I was expecting an output of DG010 SDS FILE for FILE_NAME... (6 Replies)
Hi All,
I have a fixed-width datafile from which i need to extract value/string starting from some position to the specified length in each of the lines.
awk '{print substr($0,x,y)}' datafile --- is working fine
but
awk 'BEGIN{a=0}{a=substr($0,x,y);print $a}' datafile ---is giving... (3 Replies)
Friends,
I have a file output.txt with values as below:
092307135717
061910135717
I want to know how to read this file and then assign each value to a variable.
say like
var1=092307135717
var2=061910135717
So that I can use this VAR1 and Var2 in the shell script for further processing.... (3 Replies)
As part of an expect script, I have to convert a strange user ID to a conventional UNIX ID. To do this, I read the contents of a file and do a little awk magic. Here's that bit of the expect script:
send "awk 'NF == 10 && \$NF == strange_user_id {print \$(NF-2)}' file_with_my_info\r"
expect... (0 Replies)
Hello
I am using unix CLI commands for the Synergy CM software. The command basically searches for a folder ID and returns the names of the projects the folder sits in. The result is assigned to a variable:
FIND_USE=`ccm folder -fu -u -f "%name"-"%version" ${FOLDER_ID}`
When the command... (6 Replies)
Hi,
The following command runs on in the Korn shell prompt. however i want to output the value of this to a variable. Can anyone provide a solution?
echo 'ABC,DEF,"G,HI,J",KLM,"MNi,O"'| awk -F "\"" '{for(i=1;i<=NF;i++){if(i%2)gsub("\,","~^~",$i)}}1' (2 Replies)
Hi All,
I am getting the output for the following command when i run it on the unix console.
---------------------------
grep `whoami` /etc/passwd | awk '{print ($1);}' | cut -d ":" -f3
----------------------------
But i made it into a script and tried to print the variable, its... (5 Replies)