由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Unix版 - 请教:Variable in sed command
相关主题
A question for highhands..怎么从script中把环境变量传回到当前shell中? (转载)
Perl help: open a very large fileDD weijing!
[转载] ask a question.where can I find some good website for C Shell ?
帮帮忙,用C作一个SHELL为什么我就是不会写Shell script?
C++5.0的初级问题How to set environment variables for CGI scripts?
how to get rid of the ^M in files?help shell script (waiting on line)
[转载] command to save outputhow to get the backgroup run state?
Help: convert // to /* */ in C code?a painful problem
相关话题的讨论汇总
话题: src话题: bpp话题: sed话题: variable话题: command
进入Unix版参与讨论
1 (共1页)
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
1 (共1页)
进入Unix版参与讨论
相关主题
a painful problemC++5.0的初级问题
Shell script problem? (转载)how to get rid of the ^M in files?
在ksh,和source类似的command是什么?[转载] command to save output
help me with a console opening problemHelp: convert // to /* */ in C code?
A question for highhands..怎么从script中把环境变量传回到当前shell中? (转载)
Perl help: open a very large fileDD weijing!
[转载] ask a question.where can I find some good website for C Shell ?
帮帮忙,用C作一个SHELL为什么我就是不会写Shell script?
相关话题的讨论汇总
话题: src话题: bpp话题: sed话题: variable话题: command