LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-28-2016, 03:22 AM   #1
habdulsalam
LQ Newbie
 
Registered: Feb 2016
Posts: 3

Rep: Reputation: Disabled
bash script to convert a file


I have a file (totalenergy.dat) containing the lattice constants and total energies per atom and i want to convert it to to a file (cohesive.dat) containing atomic volumes and cohesive energies by the script. How do i write the script?
where the cohesive energy = (total energy per unit cell/number of atoms)-energy per atom
 
Old 02-28-2016, 05:33 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Show some example data both what you start with and your desired results.

Then show us what you have tried an where you are stuck?
 
2 members found this post helpful.
Old 02-28-2016, 05:43 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
My thinking was:
who is getting paid to produce the results here ?.

determine your constants, determine your variables, do the maths.
Don't expect us to do it for you.
 
1 members found this post helpful.
Old 02-29-2016, 01:54 AM   #4
aragorn2101
Member
 
Registered: Dec 2012
Location: Mauritius
Distribution: Slackware
Posts: 567

Rep: Reputation: 301Reputation: 301Reputation: 301Reputation: 301
Hello there,

To be frank with you, you could have formulated your question otherwise; you could have placed a sample of your data file here and asked about the tools in a Linux system which could help you solve your problem.

Anyway, I think Bash is not best suited for your problem, because, even if you can do arithmetics in Bash, it is highly dependent on other utilities for doing the math as Bash is not intended for that in the first place.

What other languages do you know? C, Python, FORTRAN?
 
1 members found this post helpful.
Old 02-29-2016, 03:17 AM   #5
habdulsalam
LQ Newbie
 
Registered: Feb 2016
Posts: 3

Original Poster
Rep: Reputation: Disabled
Hello there
First of all nobody is getting paid, the arithemric is not the problem here, I need the FHI-aims bash script so that I will do all my work using FHI-aims.
Attached Thumbnails
Click image for larger version

Name:	cc.png
Views:	19
Size:	5.2 KB
ID:	20979   Click image for larger version

Name:	cc1.png
Views:	17
Size:	4.5 KB
ID:	20980  
 
Old 02-29-2016, 03:45 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
So now we have the formula and the original input ... good start

What does the desired output look like and as asked above, what if any languages do you know?

Not sure if anyone else does, but I am also unfamiliar with what 'FHI-aims' is?? (it may not be important)

I will advise that whilst you could do this in bash and use bc, I would probably pick a language that can perform decimal arithmetic itself.
Suggestions would be something like :- awk, perl, python, ruby,...
 
2 members found this post helpful.
Old 02-29-2016, 07:21 PM   #7
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,624

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
NASA/JPL released a python based toolkit
"data Productivity ToolKit"
https://oodt.jpl.nasa.gov/wiki/display/OPENSOURCE/Home

hosted on SF
https://sourceforge.net/projects/dptoolkit/

it might help
 
Old 02-29-2016, 07:51 PM   #8
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by grail View Post
So now we have the formula and the original input ... good start

What does the desired output look like and as asked above, what if any languages do you know?

Not sure if anyone else does, but I am also unfamiliar with what 'FHI-aims' is?? (it may not be important)

I will advise that whilst you could do this in bash and use bc, I would probably pick a language that can perform decimal arithmetic itself.
Suggestions would be something like :- awk, perl, python, ruby,...
I don't even think bash does floating point, if I remember correctly... especially with E left overs, but I could be wrong.

OP would be better off trying @John VV Idea post #7 unless pascal might work for OP,
Lazarus and open pascal got graphs too. make it look all fancy like even.

Open Pascal is an easy programming language to learn. IMO and lots others too.

. As noted by others, bash does not support floating point arithmetic.

Last edited by BW-userx; 02-29-2016 at 07:57 PM.
 
Old 02-29-2016, 11:42 PM   #9
habdulsalam
LQ Newbie
 
Registered: Feb 2016
Posts: 3

Original Poster
Rep: Reputation: Disabled
Thanks, I was able to solve the problem using awk
 
Old 03-01-2016, 09:08 AM   #10
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
So please post your solution for others to learn from your experience

Also, please mark as SOLVED now you have a solution.
 
Old 03-01-2016, 09:23 AM   #11
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
he said Please....
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to convert a hexadecimal to timestamp via bash script ? nab_elf Linux - Desktop 7 08-28-2013 06:51 AM
how to convert bash script to binary? dwarf007 Programming 3 07-24-2012 07:07 AM
[SOLVED] stuck at bash script to convert files with ffmpeg panseluta Linux - Newbie 6 03-10-2011 09:20 AM
convert tcsh script to the bash one fazanpai Linux - Software 2 11-29-2009 08:10 AM
Convert a Bash script to C Linh Programming 5 04-25-2004 12:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:00 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration