小编dwt*_*bar的帖子

从文件中剪切空行(bash 脚本)

我试图摆脱文件中的所有空行,但我确实想在每个非空行之后保留“\n”。

问题:如果在 CLI 中使用,命令可以正常工作,但是一旦我在 bash 脚本中使用任何命令,它就会删除所有“\n”,因此我将所有结果放在一行中,而不是将它们放在单独的行中。

这是我的代码:

#printing second and third word from every line and remove lines that do not contain any digits
    result=$(cat "$output_file" | awk '{print $2" "$3}' | sed 's/[^0-9]*/\\n/')
    echo -e ""$result"" > "$output_file"

#getting rid of all empty lines but what happens is that the whole file becomes one line
    no_empty_lines=$(cat "$output_file" | awk NF)
    echo -e ""$no_empty_lines"" > "$output_file"
Run Code Online (Sandbox Code Playgroud)

要编辑的文件:

> 135.121.62.246 7.4 
> 135.121.160.65 7.8 
> 135.121.106.56 7.5 
>  
>  
> 135.121.106.96 …

linux bash

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

并行:警告:没有更多文件句柄

我正在运行 GNU 并行,一段时间后我得到:

parallel: Warning: no more file handles Raising ulimit -n or etc/security/limits.conf may help.
Run Code Online (Sandbox Code Playgroud)

为了克服这个问题,应该向并行命令添加什么参数?

我更改limits.conf为,unlimited但后来我无法使用sudo或登录我的盒子,同样的问题root就像这里ssh

这是我正在使用的代码片段。我有 2 个文件,第一个带有密码,第二个带有主机。

passPasswords_and_hosts() {
        `sudo sshpass -p "$1" ssh -o ConnectTimeout=2 root@"$2" -o StrictHostKeyChecking=no "$command_linux"`
}
export -f testone
export -p command_linux
parallel --tag -k passPasswords_and_hosts :::: "$passwords" "$linux_hosts"
Run Code Online (Sandbox Code Playgroud)

ulimit gnu-parallel

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

标签 统计

bash ×1

gnu-parallel ×1

linux ×1

ulimit ×1