简体   繁体   中英

Find and Replace with parameter in Linux

I have many files that contain line like this one:

_str = floatNumber_ (including spaces)

And I would like multiply that float by a constant and have the result there like:

_str = 4xfloatNumber_

How to do that?

You can do it with awk :

awk 'BEGIN{FS="="};{print $1 "= " 4*$2}' < src_file > dest_file

Details:

  • BEGIN{FS="="} : define = as field separator,
  • {print $1 "= " 4*$2} make the operation you want,
  • < src_file : read data from src_file ,
  • > dest_file : write data to dest_file .

And if you have several files to process:

# where *.* are the files you want to process
for i in *.* 
do
    awk 'BEGIN{FS="="};{print $1 "= " 4*$2}' < $i > $i.out
done

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM