r*****s 发帖数: 985 | 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! | m*******t 发帖数: 40 | 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.
| r*****o 发帖数: 28 | 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
|
|