#teststr="IBM"

#sed -n '/' "$teststr" '/=' testfile.txt

在sed中使用变量

通常,我们使用sed进行变量替换的时候,替换和被替换变量都是hard-coded的。例如:

sed -n ‘/comm/p’ /tmp/test.log

如果我们用一变量var,它的值根据上下文变化

$ var=”comm”,定义了变量,那么我们在sed的使用中这样使用变量

$ sed -n ‘/’”$var”‘/p’ /tmp/test.log

注意,是用单引号包含双引号来引用变量。

 

相关文章:

  • 2021-10-14
  • 2022-12-23
  • 2021-12-12
  • 2022-12-23
  • 2022-12-23
  • 2023-02-14
  • 2022-02-09
猜你喜欢
  • 2021-05-28
  • 2021-06-25
  • 2022-12-23
  • 2021-07-18
  • 2021-07-01
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案