0

I have a file named params.txt and the content in the file will be %test(dir='/home/spread',src=tab1,tgt=tab1,sch=xyz);

I need a shell script where i will be passing these 4 parameters while calling the script. File params.txt has to be updated with whatever i pass. For example,

params.sh '/tmp/category' emp emp hr

Before replacement:

%test(dir='/home/spread',src=tab1,tgt=tab1,sch=xyz);

After replacement:

%test(dir='/tmp/category',src=emp,tgt=emp,sch=hr);

I will be calling the script multiple times and the parameters need to be updated with whatever is passed while executing the script.

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • it is a sas based script that I need to call using shell script. I am using a macro to call the parameters that are mentioned in the file. I tried using "sed" to replace but i was not sure how to use regex to parse only required fields – aloneonthe_edge Feb 15 '19 at 09:17

1 Answers1

1

Sounds like you are simply looking for

#!/bin/sh
printf "%%test(dir='%s',src=%s,tgt=%s,sch=%s);\n" "$@" >params.txt
tripleee
  • 175,061
  • 34
  • 275
  • 318
  • Worked like a charm. Thank you so much tripleee. what does "$@" donote? – aloneonthe_edge Feb 15 '19 at 12:56
  • The command-line parameters, as a properly quoted list. Google allows you to [search for "dollar-at bash"](https://www.google.com/search?q=dollar-at+bash) these days; my top hit is [this canonical answer from Stack Overflow.](/questions/5163144/what-are-the-special-dollar-sign-shell-variables) – tripleee Feb 15 '19 at 12:58