0

I have the following file in my home area on my terminal.

hi.txt

With contents:

Site            : xyz
Observer        : xyz
Proposal        : xyz
Array Mode      : xyz
Observing Mode  : xyz
Date            : a
Num Antennas    : xyz
Antenna List    : xyz
Num bits/sample : xyz
Data Format     : xyz
Polarizations   : xyz
MJD             : xyz
UTC             : b 
Source          : xyz

I want to create a bash script which replaces the a and b values with values I input in the terminal in my data directory and writes the same there with the new values I input.

Is there a way to do this? I am very new to scripting with bashrc.

nikita0509
  • 31
  • 6
  • What do you mean by `bashrc` script? `.bashrc` is a script that runs automatically when your shell starts. Do you mean you want to do this every time you login? – Barmar Aug 10 '21 at 06:10
  • You can do the replacement with `sed` or `awk`. – Barmar Aug 10 '21 at 06:12
  • See [sed substitution with bash variables](https://stackoverflow.com/questions/7680504/sed-substitution-with-bash-variables) – Barmar Aug 10 '21 at 06:13
  • @nikita0509 : Since your input has a pretty regular format, I would use `awk`, setting the field separator to a colon. See for instance [here](https://www.grymoire.com/Unix/Awk.html). – user1934428 Aug 10 '21 at 06:18

0 Answers0