- 論壇徽章:
- 0
|
5可用積分
輸入:
參數(shù)1: Insufficient free space in the %s directory. The free space is only %s. At least %s is required.
參數(shù)2: /export/home
參數(shù)3: 5%
參數(shù)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出現(xiàn)的個數(shù)與指定要替換的字符串個數(shù)相同, 但指定要替換的字符串個數(shù)是不定的,同時要替換的字符串內(nèi)容也不定。
本想用awk接收外部參數(shù)(指定要替換的字符串), 然后以%s作為分隔符,在每個域后面加上指定的字符串,但不知道如何將不定參數(shù)傳入到awk中。
也考慮過用sed循環(huán)替換其中的%s, 但是由于 指定的參數(shù)內(nèi)容不確定,可能就包括了sed指定的分隔符。
有沒有較好的替換方式,求大神指點。 |
|