avatar
请教:Variable in sed command# Unix - 噫吁兮,危乎高哉
r*s
1
Hi, everybody,
I tried to use a shell script to do a for loop:
#!...bash
for i in (5, 10, 15, 20) do;
sed 's/bpp=64/bpp=$i/g' myfile.c > myfile2.c
~~
done
However, each time it executes, "bpp=64" becomes "bpp=$i" instead of
"bpp=5" ......
I have no idea how to make the $i inside sed command to be a real variable.
Anybody has a suggestion for it?
Thanks a lot!
avatar
m*t
2
try sed 's/bpp=64/bpp=\$\{i\}/g' myfile.c > myfile2.c

【在 r*****s 的大作中提到】
: Hi, everybody,
: I tried to use a shell script to do a for loop:
: #!...bash
: for i in (5, 10, 15, 20) do;
: sed 's/bpp=64/bpp=$i/g' myfile.c > myfile2.c
: ~~
: done
: However, each time it executes, "bpp=64" becomes "bpp=$i" instead of
: "bpp=5" ......
: I have no idea how to make the $i inside sed command to be a real variable.

avatar
r*o
3
What if I want to use the matching variable as an index of an array?
What I wanted to do is:
infile:
SRC_1
SRC_2
SRC_3
SRC_4
SRC_5
change it to outfile:
SRC_2
SRC_3
SRC_4
SRC_1
SRC_5
(Ultimately, I will want to try all the possible sequences of
SRC_1 to SRC_5
So what I did:
set array = (2 3 4 1 5) #this array can be changed by script automatically
sed "/SRC_[1-5]/s/\([1-5]\)/$array[\1]/" infile > outfile
But it doesn't recognize \1 as the index of the array,
anyway to solve it? Thanks.

variab

【在 m*******t 的大作中提到】
: try sed 's/bpp=64/bpp=\$\{i\}/g' myfile.c > myfile2.c
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。