1

I currently have thousands of .jdx files and I've managed to find a way to get the lines I need from the files echoed into a new file. What I cant seem to do is get the additional data I need to be echoed.

This is what I hope the end result to look like..

---
title: '1,2-Pentadiene'
visible: true
---

* DATA TYPE=MASS SPECTRUM
* CAS REGISTRY NO=591-95-7
* MOLFORM=C5H8
* MW=137.3

Download JDX: [10574-36-4-Mass16b9.jdx](10574-36-4-Mass16b9.jdx)

and this is the file that its being read from..

##TITLE=1,2-Pentadiene
##JCAMP-DX=4.24
##DATA TYPE=UV/VIS SPECTRUM
##ORIGIN=INSTITUTE OF ENERGY PROBLEMS OF CHEMICAL PHYSICS, RAS
##CAS REGISTRY NO=591-95-7
##MOLFORM=C5H8
##MP=-137.3
##BP=44.9
##SOURCE REFERENCE=RAS UV No. 816
##$NIST SQUIB=1955JON/TAY228-237
##$NIST SOURCE=TSGMTE
##SPECTROMETER/DATA SYSTEM=Beckman DU
##XUNITS=Wavelength (nm)
##YUNITS=Logarithm epsilon
##XFACTOR=1.000000
##YFACTOR=1.000000
##FIRSTX=170.0000
##LASTX=199.0000
##FIRSTY=3.2
##MAXX=199
##MINX=170
##MAXY=3.38
##MINY=2.02
##NPOINTS=30
##$REF AUTHOR=Jones, L.C., Jr.; Taylor, L.W.
##$REF TITLE=Far ultraviolet absorption spectra of unsaturated and aromatic hydrocarbons
##$REF JOURNAL=Anal. Chem.
##$REF VOLUME=27
##$REF NUMBER=2
##$REF PAGE=228-237
##$REF DATE=1955
##XYPOINTS=(XY..XY)
170.0000,3.200002
171.0000,3.190000
172.0000,3.190000
173.0000,3.200000
174.0000,3.240000
175.0000,3.290000
176.0000,3.340000
177.0000,3.380000
178.0000,3.370000
179.0000,3.320000
180.0000,3.320001
181.0000,3.340000
182.0000,3.130000
183.0000,2.940000
184.0000,2.840000
185.0000,2.760000
186.0000,2.700000
187.0000,2.660000
188.0000,2.620000
189.0000,2.570000
190.0000,2.500003
191.0000,2.440000
192.0000,2.370000
193.0000,2.310000
194.0000,2.250000
195.0000,2.220000
196.0000,2.190000
197.0000,2.150000
198.0000,2.080000
199.0000,2.020000
##END=

The batch file I have come up with so far is this.

#!/bin/bash
while read -r line; do
echo \r --- > new.txt;
 echo \r visible: true >> new.txt;
        if [[ $line =~ TITLE ]] ; then echo \ title: $$line > new.txt; fi
        if [[ $line =~ DATA ]] ; then echo \ $$line >> new.txt; fi
        if [[ $line =~ CAS ]] ; then echo \ $$line >> new.txt; fi
        if [[ $line =~ MOLFORM ]] ; then echo \ $$line >> new.txt; fi
        if [[ $line =~ MW ]] ; then echo \ $$line >> new.txt; fi
 done<*.jdx
yourfilenames=`ls *.jdx`
for eachfile in $yourfilenames
do
   echo \ \($eachfile\)\[$eachfile\] >> new.txt; done

Now for the life of me I cant seem to get this to work. Before I go even more grey, is there any kind soul out there who may be able to help me out?

Thanks

  • echo \r doesn't do what you think it does. Check your code with ShellCheck – shell script analysis tool – DavidPostill Mar 21 '18 at 16:54
  • Okay thanks for the link. I removed the \r and the script runs but does not seem to pull any of the data from the .jdx.. – user3179273 Mar 21 '18 at 17:09
  • Actually.. ITS WORKING :) - Thanks for the tip on that checker!! Amazing.. – user3179273 Mar 21 '18 at 17:25
0

Now for the life of me I cant seem to get this to work.

echo \r doesn't do what you think it does.

Check your code with ShellCheck – shell script analysis tool and fix the errors/warnings:

$ shellcheck myscript

Line 3:
echo \r --- > new.txt;
     ^-- SC1012: \r is just literal 'r' here. For carriage return, use "$(printf "\r")" instead.

Line 4:
 echo \r visible: true >> new.txt;
      ^-- SC1012: \r is just literal 'r' here. For carriage return, use "$(printf "\r")" instead.

Line 11:
yourfilenames=`ls *.jdx`
              ^-- SC2006: Use $(..) instead of legacy `..`.
                  ^-- SC2035: Use ./*glob* or -- *glob* so names with dashes won't become options.

Line 14:
   echo \ \($eachfile\)\[$eachfile\] >> new.txt; done
            ^-- SC2086: Double quote to prevent globbing and word splitting.
                         ^-- SC2086: Double quote to prevent globbing and word splitting.

$ 
  • Hmm, wait. I got so far but now the second row of --- I cant get to work. – user3179273 Mar 21 '18 at 17:31
  • @user3179273 You are only echoing --- once in your bash script. – DavidPostill Mar 21 '18 at 17:34
  • Yup, I had to edit the script as it was not running. Let me see if I can get a bit further.. – user3179273 Mar 21 '18 at 17:35
  • @user3179273 Please stop trying to edit my answer. If you have new code then edit your question – DavidPostill Mar 21 '18 at 17:54
0

Okay. Finally got it sorted..

Apologies for not knowing how to use this place..

#!/bin/bash
echo --- > new.txt;
 echo visible: true >> new.txt &&
while read -r line; do
        if [[ $line =~ TITLE ]] ; then echo \ title: \'$line\' >> new.txt; fi
        if [[ $line =~ DATA ]] ; then echo \ --- >> new.txt; fi
        if [[ $line =~ DATA ]] ; then echo \ $line >> new.txt; fi
        if [[ $line =~ CAS ]] ; then echo \ $line >> new.txt; fi
        if [[ $line =~ MOLFORM ]] ; then echo \ $line >> new.txt; fi
        if [[ $line =~ MW ]] ; then echo \ $line >> new.txt; fi
 done<*.jdx
echo -en '\n' >> new.txt
echo -en '\n' >> new.txt

yourfilenames=`ls *.jdx`
for eachfile in $yourfilenames
do
   echo Download JDX \ \($eachfile\)\[$eachfile\] >> new.txt; done
        sed -i 's/##DATA TYPE/ * DATA TYPE/g' *.txt
        sed -i 's/ title: ##TITLE=/ title: /g' *.txt
        sed -i 's/##CAS/ * CAS/g' *.txt
        sed -i 's/##MOLFORM/ * MOLFORM/g' *.txt
        sed -i 's/##MW/ * MW/g' *.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.