假设有三个程序的管道:
start | middle | end
如果start和end现在是perl脚本的一部分,我如何通过perl脚本中的shell命令传输数据,以便通过middle
我尝试了以下方法(对于缺乏严格的模式表示歉意,它应该是概念的简单证明):
#!/usr/bin/perl -n
# Output of "start" stage
$start = "a b c d\n";
# This shell command is "middle"
open (PR, "| sed -E 's/a/-/g' |
我有以下输入文件:
This is just junk
stuff this should not
appear in the output
module instance1 (
.a (x),
.b (y),
.c (z)
);
Module instance2 (
.a (x),
.b (y),
.c (z)
);
So is this part of the
file so no output here
as well`<br>
I want the following output:<br>
`module instance1 (
.a (x),
我有下面的bash脚本,它对找到的每一个图像重复。它需要对所有html、css和js文件进行迭代,并替换该文件中出现的所有图像。
for image in app/www/images-theme-dark/*.png
do
echo "installing icon" $image
# extract filename from iconpath
iconfile=$(basename $image)
iconPath="images/"$(basename $image)
我有10个文件,其中包含一个柱状垂直数据,我将其转换为将一个文件与水平形式的数据合并。
文件1 :
A
B
C
B
文件2 :
P
W
R
S
文件3 :
E
U
C
S
类似于上面所述,他们将重读文件。
--我使用以下脚本合并了所有文件
cd /path/
#storing all file names to array_list to club data of all into one file
array_list=`( awk -F'/' '{print $2}' )`
for i in {array_list[@]}
do
sed
为什么sed的行为不同,取决于它是从命令行运行还是从shell脚本运行?下面是一个基本的例子:
$ cat test.txt
foo
bar
baz
$ sed -e 's/^b\(\w*\)$/q\1/g' test.txt # works as intended
foo
qar
qaz
$ cat test.sh # The exact same command
sed -e 's/^b\(\w*\)$/q\1/g' test.txt
$ bash test.sh
foo
bar
baz
现在,在我进一步研究这个问题时,\w不是POSIX中的标准BRE
我正在尝试读取一个文件,替换一个变量,或者在尚未指定的情况下将它添加到底部。
我得到了一些帮助才走到这一步:
#!/bin/bash
function replaceappend() {
if ! sed "/$2/{s//$3/;h};"'${x;/./{x;q0};x;q1}' $1
then
echo "$3" >> $1
fi
}
replaceappend "/etc/ssh/sshd_config" "Port 22" "Port 123"
但是,
我写了以下脚本:
while read ligne;
do
echo ${ligne} >> /tmp/test.conf;
other code lines but it's not our probem.
done < <(cat file.conf | sed -ne '/toto/,$p');
file.conf包含这样的数据:
test1 {
var2 {}
}
toto {
var1 {
next {}
}
}
脚本必须在文件/tmp/test.conf中写入
toto {
var1 {