0
cat file.csv | awk -F '=' '{gsub(/n/,"1",$2)};{print}' 

while replace string with number the = separator vanishing file:

a=a+b
c=n+m
o/p:
a=a+b
c 1+m

but i want o/p like

a=a+b
c=1+m
Tom Fenech
  • 72,334
  • 12
  • 107
  • 141
Srikanth
  • 11
  • 1

1 Answers1

1

Change your script to this:

awk -F '=' -v OFS='=' '{gsub(/n/,"1",$2); print}' file.csv

The default output field separator is , so if awk touches the record it will change it from = unless you specify otherwise.

I combined your two action blocks; there's no need to have two separate ones.

Tom Fenech
  • 72,334
  • 12
  • 107
  • 141
  • I was changed my script but this line working in command line but in script not working – Srikanth Oct 17 '15 at 16:37
  • actually i have two files file1=a,1 n,1 and file2=a=a+b c=n+m ,i have to change in file2 corresponding values of file1 – Srikanth Oct 17 '15 at 16:41
  • It's not a good idea to ask about one thing then change your requirement after the original problem has been solved. You should work on this yourself and do some research. If you get stuck with something specific, then maybe you can ask another question. As a general piece of advice, don't put code into comments; it's totally unreadable. – Tom Fenech Oct 17 '15 at 17:11
  • while copying in to file in loop , file not changing – Srikanth Oct 17 '15 at 17:28
  • copying is not a problem awk -F '=' -v OFS='=' '{gsub(/$var/,"$value",$2); print}' file.csv , instead of string and value I am passing variable but it is not working – Srikanth Oct 17 '15 at 17:51