Tag: bash

删除重复的条目使用Bash脚本

我想从文本文件中删除重复的条目,例如: kavitha= Tue Feb 20 14:00 19 IST 2012 (duplicate entry) sree=Tue Jan 20 14:05 19 IST 2012 divya = Tue Jan 20 14:20 19 IST 2012 anusha=Tue Jan 20 14:45 19 IST 2012 kavitha= Tue Feb 20 14:00 19 IST 2012 (duplicate entry) 有没有任何可能的方法来删除重复的条目使用Bash脚本? 期望的输出 kavitha= Tue Feb 20 14:00 19 IST 2012 sree=Tue […]

如何在文件的开头插入文本?

到目前为止,我已经能够find如何在文件的开头添加一行,但这不完全是我想要的。 我会用一个例子来展示它 文件内容 some text at the beginning 结果 <added text> some text at the beginning 这是相似的,但我不想创build任何新的线路… 如果可能,我想用sed来做。

如何为多行命令放行注释

我知道如何在Bash脚本中编写多行命令,但是如何在多行命令中为每行添加注释? CommandName InputFiles \ # This is the comment for the 1st line –option1 arg1 \ # This is the comment for the 2nd line –option2 arg2 # This is the comment for the 3nd line 但是遗憾的是,继续angular色的评论会打破命令。

如何检查进程ID(PID)是否存在

在bash脚本中,我想要执行以下操作(使用伪代码): if [ a process exists with $PID ]; then kill $PID fi 条件语句的恰当expression是什么?

bash中string的长度

你如何获得存储在variables中的string长度并将其分配给另一个variables? myvar="some string" echo ${#myvar} # 11 你如何设置另一个variables到输出11 ?

如何在Bash中逐行合并两个文件

我有两个文本文件,每个文件都包含一行这样的信息 file1.txt file2.txt ———- ——— linef11 linef21 linef12 linef22 linef13 linef23 . . . . . . 我想通过使用bash脚本的行合并这些文件行,以获得: fileresult.txt ————– linef11 linef21 linef12 linef22 linef13 linef23 . . . . . . 这怎么可以在Bash中完成?

这个bash叉炸弹是如何工作的?

根据维基百科,以下是一个非常优雅的bash叉炸弹: :(){ :|:& };: 它是如何工作的?

我如何逃避bash循环列表中的空白?

我有一个bash shell脚本循环通过某个目录的所有子目录(但不是文件)。 问题是一些目录名称包含空格。 这里是我的testing目录的内容: $ls -F test Baltimore/ Cherry Hill/ Edison/ New York City/ Philadelphia/ cities.txt 以及通过目录循环的代码: for f in `find test/* -type d`; do echo $f done 这是输出: testing/巴尔的摩 testing/樱桃 爬坡道 testing/爱迪生 testing/新 纽约 市 testing/费城 樱桃山和纽约市被视为2或3个单独的条目。 我尝试引用文件名,如下所示: for f in `find test/* -type d | sed -e 's/^/\"/' | sed -e 's/$/\"/'`; do […]

nohup和&符有什么区别?

nohup myprocess.out &或myprocess.out &设置myprocess.out在后台运行。 在closuresterminal之后,该过程仍在运行。 他们之间有什么区别?

如何testingstring存在与Bash shell的文件?

我有一个包含目录名称的文件: my_list.txt : /tmp /var/tmp 如果该名称已经存在于文件中,我想在Bash之前添加一个目录名称。