Harshal wrote:
hi, i have two molecular dynamics codes, both of them take the same input, but the in different format. let me explain,
for one code (named PinyMD) in the input file, we have,
~atom_def[\atom_typ{na}\atom_ind{ 1 } \mass{14.0067}\charge{ 0.15}] ~atom_def[\atom_typ{na}\atom_ind{ 2 } \mass{14.0067}\charge{ 0.15}] ~atom_def[\atom_typ{cr}\atom_ind{ 3 } \mass{12.0107}\charge{-0.11}] ~atom_def[\atom_typ{cw}\atom_ind{ 4 } \mass{12.0107}\charge{-0.13}] ~atom_def[\atom_typ{cw}\atom_ind{ 5 } \mass{12.0107}\charge{-0.13}] and so on........
and for other code (named NMA) the input file,
1 1 2 1 3 2 4 1 5 1 6 2 7 1 8 1 and so on....
the relation between them is very straightforwd. what appears in PinyMD's input file as "na" might be an integer 1 or "cr" be integer 2 for NMA.
i am trying to write a bash script, which will read in PinyMD input file and convert in the NMA file,
[/home/soumen/tmp] $ cat arr.sh #!/bin/bash
cat > input.txt <<-END ~atom_def[\atom_typ{na}\atom_ind{ 1 } \mass{14.0067}\charge{ 0.15}] ~atom_def[\atom_typ{na}\atom_ind{ 2 } \mass{14.0067}\charge{ 0.15}] ~atom_def[\atom_typ{cr}\atom_ind{ 3 } \mass{12.0107}\charge{-0.11}] ~atom_def[\atom_typ{cw}\atom_ind{ 4 } \mass{12.0107}\charge{-0.13}] ~atom_def[\atom_typ{cw}\atom_ind{ 5 } \mass{12.0107}\charge{-0.13}] END
tr "{}" " " <input.txt|awk 'BEGIN{n["na"]=1;n["cr"]=2;n["cw"]=3}{print $4,n[$2]}' [/home/soumen/tmp] $ bash arr.sh 1 1 2 1 3 2 4 3 5 3 [/home/soumen/tmp] $
Presuming, this is what you wanted ;)
-- Soumen Dass [Registered Linux User # 272639 - Linux nova 2.4.22-1.2115.nptl i686]
Help stamp out Mickey-Mouse computer interfaces -- Menus are for Restaurants!