- 论坛徽章:
- 0
|
5可用积分
输入:
参数1: Insufficient free space in the %s directory. The free space is only %s. At least %s is required.
参数2: /export/home
参数3: 5%
参数4: 20%
输出: Insufficient free space in the /export/home directory. The free space is only 5%. At least 20% is required.
简单描述:
给出一个源串,如:Insufficient free space in the %s directory. The free space is only %s. At least %s is required.
把其中%s替换为指定的字符串,如:/export/home, 5%, %20
可以保证%s出现的个数与指定要替换的字符串个数相同, 但指定要替换的字符串个数是不定的,同时要替换的字符串内容也不定。
本想用awk接收外部参数(指定要替换的字符串), 然后以%s作为分隔符,在每个域后面加上指定的字符串,但不知道如何将不定参数传入到awk中。
也考虑过用sed循环替换其中的%s, 但是由于 指定的参数内容不确定,可能就包括了sed指定的分隔符。
有没有较好的替换方式,求大神指点。 |
|