有没有比使用sedand更快速地获得几列值的方法awk?
举例来说,如果我有输出ls -hal /,我只想获取文件和目录名称和大小,我怎么能轻易和迅速地这样做,而不必花费几分钟的时间调整我的命令。
total 16078
drwxr-xr-x 33 root wheel 1.2K Aug 13 16:57 .
drwxr-xr-x 33 root wheel 1.2K Aug 13 16:57 ..
-rw-rw-r-- 1 root admin 15K Aug 14 00:41 .DS_Store
d--x--x--x 8 root wheel 272B Jun 20 16:40 .DocumentRevisions-V100
drwxr-xr-x+ 3 root wheel 102B Mar 27 12:26 .MobileBackups
drwx------ 5 root wheel 170B Jun 20 15:56 .Spotlight-V100
d-wx-wx-wt 2 root wheel 68B Mar 27 12:26 .Trashes
drwxrwxrwx …Run Code Online (Sandbox Code Playgroud) 我有 20 个具有相同行数的制表符分隔文件。我想选择每个文件的第 4 列,粘贴到一个新文件中。最后,新文件将有 20 列,每列来自 20 个不同的文件。
如何使用 Unix/Linux 命令执行此操作?
输入,20 个相同格式。我希望文件 1 的第 4 列在此处表示为 A1:
chr1 1734966 1735009 A1 0 0 0 0 0 1 0
chr1 2074087 2083457 A1 0 1 0 0 0 0 0
chr1 2788495 2788535 A1 0 0 0 0 0 0 0
chr1 2821745 2822495 A1 0 0 0 0 0 1 0
chr1 2821939 2822679 A1 1 0 0 0 0 0 0
...
Run Code Online (Sandbox Code Playgroud)
输出文件,有 20 列,每列来自 …
我正在尝试对齐这些列
super+t sticky toggle
super+Shift+space floating toggle
super+Shift+r restart
super+Shift+d mode $mode_launcher
super+Shift+c reload
super+r mode resize
super+Return i3-sensible-terminal
super+q kill
super+n Nautilus scratchpad show
super+m neomutt scratchpad show
super+minus scratchpad show
super+f fullscreen toggle
super+c bar mode toggle
super+button2 kill
super+alt+x systemctl -i suspend
super+alt+v cmus
super+alt+m neomutt
super+alt+c ~/bin/editinvim
super+alt+b ranger
Run Code Online (Sandbox Code Playgroud)
我试过使用,awk但没有运气。首选格式是
super+Shift+d mode $mode_launcher
super+alt+c ~/bin/editinvim
super+alt+b ranger
Run Code Online (Sandbox Code Playgroud) 我需要比较 2 个文件。两个文件中的第 1 列相同。第 2 列是我要比较的内容:在比较第 2 列时,我希望文件 1 中所有不在文件 2 中的行。两个文件中的第 3 列不同,即使是第 1 列和第 2 列相同的行。我无法删除第 3 列,因为作为输出,我想要包含此列的文件 1 中的行。
下面是一个例子:
文件 1
21 12340 3
21 12341 7
21 12342 2
21 12343 89
21 12349 7
Run Code Online (Sandbox Code Playgroud)
档案 2
21 12340 55
21 12341 7
21 12343 89
21 12344 7
21 12346 88
21 12347 3
21 12348 37
Run Code Online (Sandbox Code Playgroud)
我的输出是:
21 12342 2
21 12349 7
Run Code Online (Sandbox Code Playgroud) 我有一个c++程序,我使用制表符"\t"将我的输出组织到人类可读的列中。但是,bash 中 8 个空格宽的列对我来说太窄了。我怎样才能增加它?
注意:在 C++ 论坛中,人们说:“C++ 只输出字符,不负责可见输出”。在 linux 论坛中,人们说:“可能是您用来输出到终端的程序对此负责less。”
$ echo 'a b' | column -t
a b
Run Code Online (Sandbox Code Playgroud)
输出之间a和之间有 2 个空格b。column如果可能,如何只使用一个空间进行分隔?
编辑 2:更改数据以包含更多案例
$ cat data
1 2 b
20 12.5 something
300 12.8 as
600 16 asrgty
1200 4.9 srty
1800 33.5 sry
10000 1.5 sty
200000 1.5 sty
$ column -t < data
1 2 b
20 12.5 something
300 12.8 as
600 16 asrgty
1200 4.9 srty
1800 33.5 sry
10000 1.5 sty
200000 1.5 sty
$ column -t -s …Run Code Online (Sandbox Code Playgroud) 示例数据:
"Monday","12345","Friday"
Run Code Online (Sandbox Code Playgroud)
在上面的文件中,我想在 12345 和星期五之间添加一个新列。
我怎样才能做到这一点 ?
我正在寻找一个选项来删除具有特定文本的列,例如
“滴滴”
aaa bbb ccc ddd eee fff
1 2 3 4 5 6
2 3 4 5 6 0
Run Code Online (Sandbox Code Playgroud)
所以输出看起来像这样:
aaa bbb ccc eee fff
1 2 3 5 6
2 3 4 6 0
Run Code Online (Sandbox Code Playgroud)
我知道有一个简单的选项可以删除第 4 列并且可以完成相同的工作,但是我的 *.csv 文件没有排序。有任何想法吗?
这是 unix 的后续:用另一个文件中的单个值替换一个文件中的一整列
我试图用另一个文件 (file2) 中的一个特定值替换文件 (file1) 的一列。
file1 的结构如下:
HETATM 8 P FAD B 600 98.424 46.244 76.016 1.00 18.65
HETATM 9 O1P FAD B 600 98.634 44.801 75.700 1.00 17.69 O
HETATM 10 O2P FAD B 600 98.010 46.640 77.387 1.00 15.59 O
HETATM 11 H5B1 FAD B 600 96.970 48.950 72.795 1.00 -1.00 H
Run Code Online (Sandbox Code Playgroud)
我绝对需要保留这个结构。
file2 的结构如下:
1 27, -81.883, 4.0
5 48, -67.737, 20.0
1 55, -72.923, 4.0
4 27, -62.64, 16.0
Run Code Online (Sandbox Code Playgroud)
我注意到 awk 是“行为不当”并且丢失了我的 …
这个问题基于Ask\xe2\x80\xafUbuntu 上的 \xc2\xa0similar 问题,\n但不是bash,我\xc2\xa0 希望在 中获得类似的输出sh。
bash 中没有问题;它按预期工作。
\nwolf@linux:~$ echo $SHELL\n/usr/bin/bash\nwolf@linux:~$ \nwolf@linux:~$ varA=\'Aug 01\n> Aug 16\n> Aug 26\'\nwolf@linux:~$ \nwolf@linux:~$ varB=\'04:25\n> 03:39\n> 10:06\'\nwolf@linux:~$ \nwolf@linux:~$ echo "$varA $varB"\nAug 01\nAug 16\nAug 26 04:25\n03:39\n10:06\nwolf@linux:~$\nwolf@linux:~$ paste <(printf %s "$varA") <(printf %s "$varB")\nAug 01 04:25\nAug 16 03:39\nAug 26 10:06\nwolf@linux:~$\nRun Code Online (Sandbox Code Playgroud)\n但是,当我在 中尝试类似的命令时sh,我收到以下错误。
wolf@linux:~$ sh\n$ \n$ varA=\'Aug 01\n> Aug 16\n> Aug 26\'\n\n$ varB=\'04:25\n> 03:39\n> 10:06\'\n$ \n$ echo "$varA $varB"\nAug 01\nAug 16\nAug 26 04:25\n03:39\n10:06\n$ \n$ paste <(printf …Run Code Online (Sandbox Code Playgroud)