小编gle*_*man的帖子

如何在bash中删除pom文件中的版本号

我有一个pom文件,其中包含以下信息:

<modelVersion>4.0.0</modelVersion>
  <groupId>com.site.camera</groupId>
  <artifactId>proj3</artifactId>
  <packaging>pom</packaging>
  <version>2.6</version>
  <name>Proj 3</name>
Run Code Online (Sandbox Code Playgroud)

我正在编写一个bash脚本,并希望能够打开这个文件(pom.xml)并删除版本(例如在这种情况下为2.6).我这样做是因为当我更新版本时,我希望我的脚本的其余部分用它来更新.

我尝试过的事情:

var=$(grep <version>2.6</version> pom.xml)
echo $var
Run Code Online (Sandbox Code Playgroud)

请注意,我在pom文件中有多个版本参数.我需要这个特定的版本,包含这个名称,包装,artifactId等.

xml bash grep sed maven

3
推荐指数
2
解决办法
4897
查看次数

在php中运行并忘记系统调用

所以我试图从我的PHP代码执行一些脚本.它位于页面blah.php中

<?php
     // ....
     // just basic web site that allows upload of file...
?>
Run Code Online (Sandbox Code Playgroud)

在里面我使用系统调用

if (system("blah.pl arg1") != 0)
{
   print "error\n";
}
else
{
   print "working on it..you will receive e-mail at completion\n";
}
Run Code Online (Sandbox Code Playgroud)

工作得很好,但它一直等到它完成后才打印出来.我知道我从php调用perl脚本而不是拼写错误.

我怎样才能开始执行程序并让它在后台完成.blah.pl脚本处理电子邮件通知.

任何人?

谢谢,我很感激

php system-calls

2
推荐指数
1
解决办法
3508
查看次数

在egrep中使用OR

如何仅选择以任何数字开头的行或带有几颗星的" **SETTLE"字?以下将返回以数字开头的行,但不返回带有SETTLE一词的行.

# cat somefile.txt | egrep "(^[0-9]|'^*************** SETTLE ')"
Run Code Online (Sandbox Code Playgroud)

grep

2
推荐指数
1
解决办法
6491
查看次数

使用日期命名tar文件

我想用日期命名一个tar文件,但我尝试的是不起作用,请参阅下面的代码以获得更好的解释,以及ai必须做什么?

date=$( date +%Y-%m-%d_%H:%M:%S )
tar -czf ${imageName-$date}.tar.gz ${imageBasename} 2>>$ERRORLOG
Run Code Online (Sandbox Code Playgroud)

图像名称是存储图像名称的变量,如: win-ser-rdp

我也试过了:

tar -czf ${imageName}:${date}.tar.gz ${imageBasename} 2>>$ERRORLOG
Run Code Online (Sandbox Code Playgroud)

也没有工作:(

感谢所有的帮助:D

linux shell date tar

2
推荐指数
2
解决办法
4684
查看次数

如何使用awk将两个模式之间的未知数量的多行合并为一行

我有一些文本文件,其中每个文件将有如下信息

235.91 245.67 B: some information here
246.79 246.99 A: some other information here,
more information here,
and may be here
247.45 248.99 A: some other text here,
some more here
249.98 ---- 
Run Code Online (Sandbox Code Playgroud)

并且模式重复

我希望文本安排如下:

235.91 245.67 B: some information here
246.79 246.99 A: some other information here, more information here, and may be here
247.45 248.99 A: some other text here. some more here
249.98 -----
Run Code Online (Sandbox Code Playgroud)

这意味着我想合并两个匹配模式之间的所有行(它们之间有空格)

我希望每一行都以数字作为模式开始.数字始终有一个小数点,小数点后有两位数.图案与下一个图案之间的线数不同(可以有一条或多条线或根本没有线).

有人可以使用shell脚本帮助我这样做,最好使用awk吗?

shell awk grep

2
推荐指数
1
解决办法
1490
查看次数

Tcl 8.4数组键设置不能接受内联函数调用

在其他动态类型,交错语言(Ruby,PERL ...)中,可以将哈希中的键定义为函数调用的内联.例如(在Ruby中:

a[ foo(1) ] = bar
Run Code Online (Sandbox Code Playgroud)

我试图在Tcl 8.4中做同样的事情,但失败了,请参阅下面的tclsh日志:

% proc add1 { x } { expr {$x + 1 } }
% array set p {}
% set p( [add1 1]) 0
wrong # args: should be "set varName ?newValue?"
Run Code Online (Sandbox Code Playgroud)

不用说,我将一个变量分配给add1 1的输出,并使用变量值,它确实有效:

% set a [add1 1]
2
% set p($a) 0
0
Run Code Online (Sandbox Code Playgroud)

毫无疑问,这是一个风格问题,但我喜欢内联函数,而不是使用中间变量.有什么建议?

arrays tcl

2
推荐指数
1
解决办法
64
查看次数

使用`lmap`过滤字符串列表

假设我想从列表中获取所有5个字母的单词.

set words {apple banana grape pear peach}
lmap word $words {if {[string length $word] == 5} {expr {"$word"}} else continue}
# ==> apple grape peach
Run Code Online (Sandbox Code Playgroud)

我对引用的混乱不满意expr {"$word"}.我希望这会奏效:

lmap word $words {if {[string length $word] == 5} {return $word} else continue}
# ==> apple
Run Code Online (Sandbox Code Playgroud)

什么是从lmap主体"返回"字符串的优雅方式?

tcl

2
推荐指数
1
解决办法
1308
查看次数

Perl one-liner:如何跳转到@ARGV中的下一个文件

我在想如何在perl -ne循环中"短路"读取文件.如果我遇到某种情况,我想放弃当前文件并继续进入@ARGV中的下一个文件.这与GNU awk的方便nextfile命令类似.

像这样的东西:

perl -ne 'do_something(); next_file if some_condition()' files ...
Run Code Online (Sandbox Code Playgroud)

到处玩,我发现close ARGV实现了"转到下一个档案"的目标.

还有其他不那么神奇的方法来实现这个目标吗?

perl

2
推荐指数
1
解决办法
254
查看次数

如何在自身内部获取鱼类脚本的路径

在bash中,我们可以获取脚本的路径$0.$_根据官方文件,似乎我们可以在鱼脚本中做到这一点.

但是,如果我尝试编写这样的鱼脚本并运行它,它将只打印一个换行符.

#!/usr/bin/fish
echo $_
Run Code Online (Sandbox Code Playgroud)

在反应性鱼类中,echo $_会给予echo文字,并且<command> $_会将"命令"明确地作为<command>论点.

$_对它的奇怪行为以及它的用途感到困惑.

shell fish

2
推荐指数
1
解决办法
123
查看次数

2
推荐指数
1
解决办法
180
查看次数

标签 统计

grep ×3

shell ×3

bash ×2

tcl ×2

arrays ×1

awk ×1

date ×1

fish ×1

linux ×1

maven ×1

perl ×1

php ×1

sed ×1

system-calls ×1

tar ×1

xml ×1