Skip to main content
Fixed the spelling mistake in title and higlhighted the difference between input and output file name.
Source Link

Find and replace diferentdifferent columns using awk

I try to make a change in a file: find

Find a certain value and substitute it with another value in a different column using awk:.

Input (UiO-66Zr-EH.mof):

unit ntype qqatom
  1  'Zr1'  0.0d0
vibration
0
improper
0
unit ntype qqatom
  2  'H1'  0.0d0
vibration
0
improper
0
unit ntype qqatom
  3  'C25'  0.0d0
vibration
0
improper
0
unit ntype qqatom
  4  'O1'  0.0d0

Output (output):

unit ntype qqatom
  1  'Zr1'  2.222d0
vibration
0
improper
0
unit ntype qqatom
  2  'H1'  3.333d0
vibration
0
improper
0
unit ntype qqatom
  3  'C25'  7.456d0
vibration
0
improper
0
unit ntype qqatom
  4  'O1'  9.99d0

I've tried this command:

awk < UiO-66Zr-EH.mof '$2 ~ /Zr1/ {$3 ="2.222.d0"}1''$2 ~ /O1/ {$3 ="9.99d0"}1''$2 ~ /C25/ {$3 ="7.45d0"}1''$2 ~ /H1/ {$3 ="3.333d0"}1' > output

But it didn't function very well. 

Can I do that with awk and keep, while also keeping the same formation also?

Find and replace diferent columns using awk

I try to make a change in a file: find a certain value and substitute it with another value in a different column using awk:

Input

unit ntype qqatom
  1  'Zr1'  0.0d0
vibration
0
improper
0
unit ntype qqatom
  2  'H1'  0.0d0
vibration
0
improper
0
unit ntype qqatom
  3  'C25'  0.0d0
vibration
0
improper
0
unit ntype qqatom
  4  'O1'  0.0d0

Output

unit ntype qqatom
  1  'Zr1'  2.222d0
vibration
0
improper
0
unit ntype qqatom
  2  'H1'  3.333d0
vibration
0
improper
0
unit ntype qqatom
  3  'C25'  7.456d0
vibration
0
improper
0
unit ntype qqatom
  4  'O1'  9.99d0

I've tried this command:

awk < UiO-66Zr-EH.mof '$2 ~ /Zr1/ {$3 ="2.222.d0"}1''$2 ~ /O1/ {$3 ="9.99d0"}1''$2 ~ /C25/ {$3 ="7.45d0"}1''$2 ~ /H1/ {$3 ="3.333d0"}1' > output

But it didn't function very well. Can I do that with awk and keep the same formation also?

Find and replace different columns using awk

I try to make a change in a file:

Find a certain value and substitute it with another value in a different column using awk.

Input (UiO-66Zr-EH.mof):

unit ntype qqatom
  1  'Zr1'  0.0d0
vibration
0
improper
0
unit ntype qqatom
  2  'H1'  0.0d0
vibration
0
improper
0
unit ntype qqatom
  3  'C25'  0.0d0
vibration
0
improper
0
unit ntype qqatom
  4  'O1'  0.0d0

Output (output):

unit ntype qqatom
  1  'Zr1'  2.222d0
vibration
0
improper
0
unit ntype qqatom
  2  'H1'  3.333d0
vibration
0
improper
0
unit ntype qqatom
  3  'C25'  7.456d0
vibration
0
improper
0
unit ntype qqatom
  4  'O1'  9.99d0

I've tried this command:

awk < UiO-66Zr-EH.mof '$2 ~ /Zr1/ {$3 ="2.222.d0"}1''$2 ~ /O1/ {$3 ="9.99d0"}1''$2 ~ /C25/ {$3 ="7.45d0"}1''$2 ~ /H1/ {$3 ="3.333d0"}1' > output

But it didn't function very well. 

Can I do that with awk, while also keeping the same formation?

deleted 155 characters in body
Source Link
Joao Macau
  • 225
  • 1
  • 4
  • 11

I try to make a change in a file: find a certain value and substitute it with another value in a different column using awk:

Input

unit ntype qqatom
  1  'Zr1'  0.0d0
vibration
0
improper
0
unit ntype qqatom
  2  'H1'  0.0d0
vibration
0
improper
0
unit ntype qqatom
  3  'C25'  0.0d0
vibration
0
improper
0
unit ntype qqatom
  4  'O1'  0.0d0

Output

unit ntype qqatom
  1  'Zr1'  2.222d0
vibration
0
improper
0
unit ntype qqatom
  2  'H1'  3.333d0
vibration
0
improper
0
unit ntype qqatom
  3  'C25'  7.456d0
vibration
0
improper
0
unit ntype qqatom
  4  'O1'  9.99d0

I've tried this command:

awk < UiO-66Zr-EH.mof '$2 ~ /Zr1/ {$3 ="2.008222.d0"}1''$2 ~ /O25/ {$3 ="-1.179d0"}1''$2 ~ /O1/ {$3 ="-0="9.582d0"99d0"}1''$2 ~ /C25/ {$3 ="-0.121d0"}1''$2 ~ /C13 / {$3 ="-0.002d0"}1''$2 ~ /"C1 "/ {$3 ="0.625d0"}1''$2 ~ /O29/ {$3 ="-0="7.741d0"45d0"}1''$2 ~ /H1/ {$3 ="0.127d0"}1''$2 ~ /H25/ {$3 ="0="3.495d0"333d0"}1' > output

But it didn't function very well. Can I do that with awk and keep the same formation also?

I try to make a change in a file: find a certain value and substitute it with another value in a different column using awk:

Input

unit ntype qqatom
  1  'Zr1'  0.0d0
vibration
0
improper
0
unit ntype qqatom
  2  'H1'  0.0d0
vibration
0
improper
0
unit ntype qqatom
  3  'C25'  0.0d0
vibration
0
improper
0
unit ntype qqatom
  4  'O1'  0.0d0

Output

unit ntype qqatom
  1  'Zr1'  2.222d0
vibration
0
improper
0
unit ntype qqatom
  2  'H1'  3.333d0
vibration
0
improper
0
unit ntype qqatom
  3  'C25'  7.456d0
vibration
0
improper
0
unit ntype qqatom
  4  'O1'  9.99d0

I've tried this command:

awk < UiO-66Zr-EH.mof '$2 ~ /Zr1/ {$3 ="2.008.d0"}1''$2 ~ /O25/ {$3 ="-1.179d0"}1''$2 ~ /O1/ {$3 ="-0.582d0"}1''$2 ~ /C25/ {$3 ="-0.121d0"}1''$2 ~ /C13 / {$3 ="-0.002d0"}1''$2 ~ /"C1 "/ {$3 ="0.625d0"}1''$2 ~ /O29/ {$3 ="-0.741d0"}1''$2 ~ /H1/ {$3 ="0.127d0"}1''$2 ~ /H25/ {$3 ="0.495d0"}1' > output

But it didn't function very well. Can I do that with awk and keep the same formation also?

I try to make a change in a file: find a certain value and substitute it with another value in a different column using awk:

Input

unit ntype qqatom
  1  'Zr1'  0.0d0
vibration
0
improper
0
unit ntype qqatom
  2  'H1'  0.0d0
vibration
0
improper
0
unit ntype qqatom
  3  'C25'  0.0d0
vibration
0
improper
0
unit ntype qqatom
  4  'O1'  0.0d0

Output

unit ntype qqatom
  1  'Zr1'  2.222d0
vibration
0
improper
0
unit ntype qqatom
  2  'H1'  3.333d0
vibration
0
improper
0
unit ntype qqatom
  3  'C25'  7.456d0
vibration
0
improper
0
unit ntype qqatom
  4  'O1'  9.99d0

I've tried this command:

awk < UiO-66Zr-EH.mof '$2 ~ /Zr1/ {$3 ="2.222.d0"}1''$2 ~ /O1/ {$3 ="9.99d0"}1''$2 ~ /C25/ {$3 ="7.45d0"}1''$2 ~ /H1/ {$3 ="3.333d0"}1' > output

But it didn't function very well. Can I do that with awk and keep the same formation also?

Fixed spelling and grammar, made it more clear, improved formatting
Source Link

find Find and replaced in diferentsreplace diferent columns using awk

I try to make a change in a file that correspond in finding: find a certain value and substituted othersubstitute it with another value in othera different column using awk comandawk:

INPUTInput

unit ntype qqatom
  1  'Zr1'  0.0d0
vibration
0
improper
0
unit ntype qqatom
  2  'H1'  0.0d0
vibration
0
improper
0
unit ntype qqatom
  3  'C25'  0.0d0
vibration
0
improper
0
unit ntype qqatom
  4  'O1'  0.0d0

OUTPUTOutput

unit ntype qqatom
  1  'Zr1'  2.222d0
vibration
0
improper
0
unit ntype qqatom
  2  'H1'  3.333d0
vibration
0
improper
0
unit ntype qqatom
  3  'C25'  7.456d0
vibration
0
improper
0
unit ntype qqatom
  4  'O1'  9.99d0

I've trytried this command:

awk < UiO-66Zr-EH.mof '$2 ~ /Zr1/ {$3 ="2.008.d0"}1''$2 ~ /O25/ {$3 ="-1.179d0"}1''$2 ~ /O1/ {$3 ="-0.582d0"}1''$2 ~ /C25/ {$3 ="-0.121d0"}1''$2 ~ /C13 / {$3 ="-0.002d0"}1''$2 ~ /"C1 "/ {$3 ="0.625d0"}1''$2 ~ /O29/ {$3 ="-0.741d0"}1''$2 ~ /H1/ {$3 ="0.127d0"}1''$2 ~ /H25/ {$3 ="0.495d0"}1' > output

But it didn't functionalfunction very well :s can i. Can I do that with awk and keep the same fomationformation also?

find and replaced in diferents columns using awk

I try to make a change in a file that correspond in finding a certain value and substituted other value in other different column using awk comand:

INPUT

unit ntype qqatom
  1  'Zr1'  0.0d0
vibration
0
improper
0
unit ntype qqatom
  2  'H1'  0.0d0
vibration
0
improper
0
unit ntype qqatom
  3  'C25'  0.0d0
vibration
0
improper
0
unit ntype qqatom
  4  'O1'  0.0d0

OUTPUT

unit ntype qqatom
  1  'Zr1'  2.222d0
vibration
0
improper
0
unit ntype qqatom
  2  'H1'  3.333d0
vibration
0
improper
0
unit ntype qqatom
  3  'C25'  7.456d0
vibration
0
improper
0
unit ntype qqatom
  4  'O1'  9.99d0

I've try this command:

awk < UiO-66Zr-EH.mof '$2 ~ /Zr1/ {$3 ="2.008.d0"}1''$2 ~ /O25/ {$3 ="-1.179d0"}1''$2 ~ /O1/ {$3 ="-0.582d0"}1''$2 ~ /C25/ {$3 ="-0.121d0"}1''$2 ~ /C13 / {$3 ="-0.002d0"}1''$2 ~ /"C1 "/ {$3 ="0.625d0"}1''$2 ~ /O29/ {$3 ="-0.741d0"}1''$2 ~ /H1/ {$3 ="0.127d0"}1''$2 ~ /H25/ {$3 ="0.495d0"}1' > output

But didn't functional very well :s can i do that with awk and keep the same fomation also?

Find and replace diferent columns using awk

I try to make a change in a file: find a certain value and substitute it with another value in a different column using awk:

Input

unit ntype qqatom
  1  'Zr1'  0.0d0
vibration
0
improper
0
unit ntype qqatom
  2  'H1'  0.0d0
vibration
0
improper
0
unit ntype qqatom
  3  'C25'  0.0d0
vibration
0
improper
0
unit ntype qqatom
  4  'O1'  0.0d0

Output

unit ntype qqatom
  1  'Zr1'  2.222d0
vibration
0
improper
0
unit ntype qqatom
  2  'H1'  3.333d0
vibration
0
improper
0
unit ntype qqatom
  3  'C25'  7.456d0
vibration
0
improper
0
unit ntype qqatom
  4  'O1'  9.99d0

I've tried this command:

awk < UiO-66Zr-EH.mof '$2 ~ /Zr1/ {$3 ="2.008.d0"}1''$2 ~ /O25/ {$3 ="-1.179d0"}1''$2 ~ /O1/ {$3 ="-0.582d0"}1''$2 ~ /C25/ {$3 ="-0.121d0"}1''$2 ~ /C13 / {$3 ="-0.002d0"}1''$2 ~ /"C1 "/ {$3 ="0.625d0"}1''$2 ~ /O29/ {$3 ="-0.741d0"}1''$2 ~ /H1/ {$3 ="0.127d0"}1''$2 ~ /H25/ {$3 ="0.495d0"}1' > output

But it didn't function very well. Can I do that with awk and keep the same formation also?

added 138 characters in body
Source Link
cuonglm
  • 158.1k
  • 41
  • 342
  • 420
Loading
Source Link
Joao Macau
  • 225
  • 1
  • 4
  • 11
Loading