如果你看看这个awk测试的输出,你会看到arrayin awk似乎是以某种随机模式打印出来的.对于相同数量的输入,它似乎是相同的顺序.它为什么这样做?
echo "one two three four five six" | awk '{for (i=1;i<=NF;i++) a[i]=$i} END {for (j in a) print j,a[j]}'
4 four
5 five
6 six
1 one
2 two
3 three
Run Code Online (Sandbox Code Playgroud)
echo "P04637 1A1U 1AIE 1C26 1DT7 1GZH 1H26 1HS5 1JSP 1KZY 1MA3 1OLG 1OLH 1PES 1PET 1SAE 1SAF 1SAK 1SAL 1TSR 1TUP 1UOL 1XQH 1YC5 1YCQ" | awk '{for (i=1;i<=NF;i++) a[i]=$i} END {for (j in a) print j,a[j]}'
17 1SAF
4 1C26 …Run Code Online (Sandbox Code Playgroud) 我有大量的文件(大约500个).每个文件包含两列.每个文件的第一列相同.我想使用gawk将所有文件合并到一个文件中.
例如,
File 1
a 123
b 221
c 904
Run Code Online (Sandbox Code Playgroud)
File 2
a 298
b 230
c 102
Run Code Online (Sandbox Code Playgroud)
等等.我想要一个如下所示的最终文件:
Final file
a 123 298
b 221 230
c 904 102
Run Code Online (Sandbox Code Playgroud)
我找到了可以连接两个文件的脚本,但我需要加入多个文件.
我是bash的新手,我正在学习使用grep.
grep ^[a-z] file.txt将以小写显示以小写字母开头的
grep [a-z] file.txt所有行
无法弄清楚如何用ALL小写显示行,任何人都可以帮忙吗?
如何在shell脚本中获得以下结果?
This is line 1
This is line 2
This is line 3
This is line 4
This is line 5
This is line 6
This is line 7
This is line 8
This is line 9
...
...
Run Code Online (Sandbox Code Playgroud)
期望的输出:
This is line 1 This is line 2 This is line 3
This is line 4 This is line 5 This is line 6
This is line 7 This is line 8 This is line 9
... ... ....
... …Run Code Online (Sandbox Code Playgroud) 如果不止一次遇到这个角色,我必须用一个角色替换它.例如,我在文件中有这个:????aca,我必须用它替换它?aca.我试过了tr,但没有让它正常工作.
我有一个188万行的表和一个188万行的文本文件,如下所示:
CREATE TABLE trigram (count integer, A text, B text, C text)
time echo 'select * from trigram where C="mailman";'|sqlite3 3g.db
18.419 seconds.
time grep 'mailman$' N-Grams/3g
3.137 seconds
Run Code Online (Sandbox Code Playgroud)
或者更复杂的查询
time grep 'the [^ ]* mailman$' N-Grams/3g
2.879 seconds
time echo 'select * from trigram where A="the" and C="mailman";'|sqlite3 3g.db
15.839 seconds
Run Code Online (Sandbox Code Playgroud)
有什么方法可以加快sqlite3吗?
我有一个文本文件,其中包含以下行
\n\nABCD\n1234\nbear\nAnders \xc3\x85ngstr\xc3\xb6m\nRun Code Online (Sandbox Code Playgroud)\n\n我需要把它变成
\n\nDBCA\n4321\nraeb\nm\xc3\xb6rtsgn\xc3\x85 srednA\nRun Code Online (Sandbox Code Playgroud)\n\n我需要在命令行中执行此操作,因此我认为 AWK 是完成这项工作的最佳工具,但我可能是错的。也许可以用正则表达式替换来做到这一点?Notepad2 知道正则表达式替换。
\n\n稍后编辑:我需要在 Windows 中执行此操作(我使用的是 GNUWin32 工具),并且我需要它能够处理 Unicode 字符,例如 \xc3\x85、\xc3\xb6、\xc3\xab、\xc5\x9e、\xc4 \x94 等
\n我有一个bash变量,其值如下:
10:3.0,16:4.0,32:4.0,39:2.0,65:3.0,95:4.0,110:4.0,111:4.0,2312:1.0
Run Code Online (Sandbox Code Playgroud)
价值内没有空格.该值可以很长或很短.这里对65:3.0存在如此.比方说,我知道对的第一部分中的数字的值65.我想提取数字3.0或对65:3.0.我不知道的位置(偏移)65.
我将非常感谢能够进行此类提取的bash脚本.谢谢.
假设我在文件中有如下内容:
ASD22
0.00133272
ASD23
0.00176711
ASD24
0.00175753
Run Code Online (Sandbox Code Playgroud)
我想截断每个数字(忽略其余部分)以获得类似的结果:
ASD22
0.0013
ASD23
0.0017
ASD24
0.0017
Run Code Online (Sandbox Code Playgroud)
将“列外观”保持在输出文件中。有没有一种简单而紧凑的方法可以使用 sed 或 awk 之类的东西来做到这一点?
我正在处理大文件,我只想提取一列的值包含在另一个文件的列的值中的行.
例如,在file1中,我有10,000行看起来像这样:
Chr13998356 T C
Chr1401532 A G
Chr14021851 A T
Run Code Online (Sandbox Code Playgroud)
我有file2(100,000+行),其中我只想要文件1的第1列中第1列中的值的行.因此,对于文件2,我有:
Chr1 401530 G G 60 0 60 11
Chr1 401531 A A 60 0 60 11
Chr1 401532 A G 30 170 60 11
Run Code Online (Sandbox Code Playgroud)
我想以第三个文件结束:
Chr1 401532 A G 30 170 60 11
Run Code Online (Sandbox Code Playgroud)
此文件可以包含几到10,000行.
在R中,我会使用类似的东西df3 <- df2[df2[,1] %in% df1[,2],],但文件太大了.
有简单的UNIX解决方案吗?像使用comm这样的东西,但只匹配第一列而不是整行,这将是完美的.或者grep的东西,但同时搜索10K模式.
有任何想法吗?