简体   繁体   English

linux bash命令由空格分隔

[英]linux bash command separate by space

so I'm trying to display only columns at a time 所以我试图一次只显示列

first ls -l gives me this 首先ls -l给了我这个

drwxr-xr-x 11 stuff stuff      4096 2009-08-22 06:45 lyx-1.6.4
-rw-r--r--  1 stuff stuff  14403778 2009-10-26 02:37 lyx.tar.gz

I'm using this: 我正在使用这个:

ls -l |cut -d " " -f 1 

to get this 得到这个

drwxr-xr-x 
-rw-r--r-- 

and it displays my first column just fine. 它显示我的第一列就好了。 Then I want to see on the second column 然后我想在第二栏看到

ls -l |cut -d " " -f 2

I only get this 我只能得到这个

11

Shouldn't I get 我不应该得到

11
1

?
Why is it doing this? 它为什么这样做?

if I try 如果我试试

   ls -l |cut -d " " -f 2-3

I get 我明白了

11 stuff

There's gotta be an easier way to display columns right? 有一个更简单的方法来显示列吗?

这应该显示第二列:

ls -l | awk '{print $2}'

cut considers two sequential delimiters to have an empty field in between. cut认为两个连续的分隔符之间有一个空字段。 So the second line: 所以第二行:

-rw-r--r--  1 stuff stuff

has fields: 有字段:

1: -rw-r--r--
2: --empty field--
3: 1
etc.

You can use use column fields in cut: 您可以在剪切中使用使用列字段:

ls -l | cut -c13-14

Or you can use awk to separate fields (unlink, cut awk will treat sequential delimiters as a single delimiter). 或者您可以使用awk来分隔字段(取消链接,剪切awk会将顺序分隔符视为单个分隔符)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM