这是我输入的内容和得到的输出:
$ cat helloworld.txt
Hello World!
I'm Kanladaporn Sirithatthamrong
6480952
Run Code Online (Sandbox Code Playgroud)
但这就是我想要的输出:
Hello World!
I'm Kanladaporn Sirithatthamrong
6480952
Run Code Online (Sandbox Code Playgroud)
我应该怎么办?请问有什么建议吗?
我想知道如何使用 Bash 快速删除文本。例如,我有一个名为 file.txt 的文件,总共有 500 行。
我想删除第 80 到 146 行 - 我该怎么做?
可以执行此操作的终端命令是什么?
我们有一个内容如下的文件。
/* ----------------- pattern_1 ----------------- */
jb: pattern_1 Data: asdflj adfas Log: dir/log1
/* ----------------- pattern_2 ----------------- */
jb: pattern_2 typ: CM comm: ${dir}/DISPV mach: au_buh description: "run flag"
/* ----------------- pattern_3 ----------------- */
jb: pattern_3 typ: fw own: buh out_file: "${log}/jl.log" err: "log.err"
Run Code Online (Sandbox Code Playgroud)
该文件必须分为 3 个并创建为 3 个单独的文件,如下所示:
模式_1.txt
/* ----------------- pattern_1 ----------------- */
jb: pattern_1 Data: asdflj adfas Log: dir/log1
Run Code Online (Sandbox Code Playgroud)
模式_2.txt
* ----------------- pattern_2 ----------------- */
jb: pattern_2 typ: CM comm: ${dir}/DISPV mach: au_buh description: "run flag"
Run Code Online (Sandbox Code Playgroud)
模式_3.txt …
我有一个巨大的文本文件,其中包含散乱的 IP 地址,但不是在一个单元中
例如。
那么@192@你到底在做什么@168@在我家@10@.你不是@16@应该在这里的。
我想要的是制作一个输出文件,并在其中制作 ipadresses 文件,如下所示
1.192.168.10.16
2.192.223.22.44
etc..
Run Code Online (Sandbox Code Playgroud)
我对正则表达式有很好的理解,可以从文本文件中提取特定信息,但在这里我需要结合这些我感到困惑的地方。应该如何解决这样的问题?我正在使用 Ubuntu 12.04。
我想从 file.tsv 中给出的每一行打印 Cys 残基的模式。file.tsv 有两列:sequenceID 和 Sequence。从第二列序列开始,第一个字符“C”应打印为 C,如果下一个直接残基不是 C,则代码应打印 C#。# 对于 n 种不同的氨基酸出现,应该只出现一次。
因此,当在列中时,如果“C”后跟另一个字符,我想在“C”之后打印 #。所以如果序列列的值是 DCFRCGHCC,那么它应该打印在第三列 C#C#CC 中。
示例输入:
c32_g1_i1_ 3GQKAKLKVPVFFLHRRGSICSSFYLMFSFEIKKK*TSKN*CFVCVRVRNRERAGVKCAHVYCPMFNGTQTH*IIISSLNS
c32_g1_i1_ 6AV*TADDDLVRLCSIEHGTIHMCTLYTCCTLTVTHTYTHKTLIFACLFFFNFKGEHQIERAANRTSSM*KKHRNF*LGLLAX
Run Code Online (Sandbox Code Playgroud)
输出应该是三列:sequenceID、Sequence、Cys pattern
c32_g1_i1_3,GQKAKLKVPVFFLHRRGSICSSFYLMFSFEIKKK*TSKN*CFVCVRVRNRERAGVKCAHVYCPMFNGTQTH*IIISSLNS,C#C#C#C#C
c32_g1_i1_6,AV*TADDDLVRLCSIEHGTIHMCTLYTCCTLTVTHTYTHKTLIFACLFFFNFKGEHQIERAANRTSSM*KKHRNF*LGLLAX,C#C#CC#C
Run Code Online (Sandbox Code Playgroud) 我有一系列 txt 文件,每个文件都有许多条目。我通常使用 cat 将所有 txt 文件合并到一个输出文件中,但是它变得有点混乱,因为我无法确定它来自哪个原始 txt 文件。
我想知道是否有办法使用命令行首先按字母顺序合并所有 txt 文件,同时将后缀添加到原始条目以记录它来自的文件。
例如,假设我有 2 个 txt 文件,每个文件包含三个条目:
文件一:
Alpha
Bravo
Charlie
Run Code Online (Sandbox Code Playgroud)
文件_二:
Alpha
Bravo
Delta
Run Code Online (Sandbox Code Playgroud)
我想做的是:
添加后缀以显示它来自哪个列表:
Alpha_File_One
Alpha_File_Two
Bravo_File_One
Bravo_File_Two
Charlie_File_One
Delta_File_Two
Run Code Online (Sandbox Code Playgroud)这可能吗?
我正在编写一个脚本来使用 bash 脚本检查 mysql 数据库,我想检查表的状态是否不是“OK”,将返回表名并执行更多操作:
检查日志
table1 OK
table2 Some error here
table3 OK
table4 OK
table5 Another error
table6 OK
table7 Broken
table8 A very long error which take a 2 lines
of multiple errors
Run Code Online (Sandbox Code Playgroud)
检查.sh
# check and repair tables
mysqlcheck -u $hostUser -p$hostPasswd --all-databases --check --auto-repair >> check.log
# grep tables status, should return OK
cat check.log | grep 'OK' | awk '{print $2}'| while read status; do
# if any table does not contain OK
if …Run Code Online (Sandbox Code Playgroud) 我有一个命令,它向我输出一个具有以下模式的列表
exp_70_T8_s1
exp_71_T8_s5
exp_72_T8_s10
exp_73_T10_s1
exp_74_T10_s5
exp_75_T10_s10
...
Run Code Online (Sandbox Code Playgroud)
如何分别使用sedbash中的“_T”和“_s”或类似的东西获取“_T”和“_s”之后的数字?
输出应该是这样的
8
8
8
10
10
10
Run Code Online (Sandbox Code Playgroud)
和
1
5
10
1
5
10
Run Code Online (Sandbox Code Playgroud)
对于_T和_s分别
我的命令的第一部分如下所示:
for f in $(find . -name "someFile.txt" | sort); do echo $f; done | grep /someFolderName/
Run Code Online (Sandbox Code Playgroud)
基本上我想将命令添加到上面给出的命令中。
我试图只对与 firefox 无关的 IP 地址进行排序,并将它们写入一个文件中。我结束了这个命令行,完成了这项工作,但我想知道是否有办法做得更好。
netstat -antp | grep -E ?:80 | grep -v firefox > ipadress.txt && awk '{print $5}' ipadress.txt > ipadress1.txt
Run Code Online (Sandbox Code Playgroud)
有没有办法通过删除 :80 端口来获得更干净的输出?我使用了ipadress1.txt因为当我试图覆盖它时它不起作用。
我正在处理如下所示的程序输出:
Computer1@domain.com:randomtext1:completion of randomtext
Computer2@domain.com:randomtext4:completion of randomtext
Computer1@domain.com:randomtext3:completion of randomtext
Computer3@domain.com:randomtext2:completion of randomtext
Computer2@domain.com:randomtext5:completion of randomtext
Computer1@domain.com:randomtext6:completion of randomtext
Computer3@domain.com:randomtext7:completion of randomtext
Computer2@domain.com:randomtext8:completion of randomtext
Run Code Online (Sandbox Code Playgroud)
所以如你所见,同一台电脑会给我不止一个结果,但是每个结果在内容和长度上都是不同的(但都在一行中)。有些计算机只会给出 1 个结果,有些计算机会给出多达 15 个结果,具体取决于该计算机的活动。
我想要的是我只想看到每台计算机的一个结果而不是所有结果。我现在所做的是对它进行排序并手动删除副本,这不是很有帮助!我尝试使用诸如diff和comm 之类的命令,但没有运气(这是有道理的,因为行非常不同)。
那么,如何使用 via 终端将输出更改为与此类似:
Computer1@domain.com:randomtext1:completion of randomtext
Computer2@domain.com:randomtext4:completion of randomtext
Computer3@domain.com:randomtext2:completion of randomtext
Run Code Online (Sandbox Code Playgroud)
我脑子里的想法是,也许有一种方法可以告诉终端“比较 .com 之前或第一个之前的任何内容:并删除副本”
text-processing ×10
command-line ×9
bash ×2
sed ×2
mysql ×1
netstat ×1
perl ×1
regex ×1
scripts ×1