bash - Modify first column on my data file -


i trying modify first column on xyz file. tried awk , worked, erased lines in new file created modified data. here head of original data.

1500     atoms. timestep: 0     1 6.3115 6.3115 6.36745     2 6.3115 6.3115 9.47036     2 6.3115 3.15575 6.39316     2 3.15575 6.3115 6.39316     3 3.15575 3.15575 8.83622     4 3.15575 3.15575 3.90335     5 8.53643 8.92983 8.45625     5 4.08657 8.92983 8.45625 

i used code modify first column file:

awk 'nr==fnr{a[$1]=$2;next} {$1=a[$1]}1' reemp.txt traj300.xyz > tra300.xyz 

but new file looks

timestep: 0     pb 6.3115 6.3115 6.36745     6.3115 6.3115 9.47036     6.3115 3.15575 6.39316     3.15575 6.3115 6.39316     c 3.15575 3.15575 8.83622     n 3.15575 3.15575 3.90335     hc 8.53643 8.92983 8.45625     hc 4.08657 8.92983 8.45625 

the modification good, erased first , part of second line. problem list has 75 million lines different timesteps , configurations, , code erased same thing in every configuration.

your problem not fields in traj300.xyz can found in reemp.txt. using head of input.data can reproduce problem following reemp.txt:

1 pb 2 3 c 4 n 5 h 

the first field should replaced when field found in array. must add check in awk:

awk 'nr==fnr{a[$1]=$2;next} $1 in {$1=a[$1]}1' reempt.txt traj300.xyz 

Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -