Skip to content
Advertisement

Cutting the column including size

I want to cut the column which include the size of files . I use ls -l to view info about files in current localization . I save info about file in txt file ls -l > info.txt , and now I want to cut the column including size . I do cat info.txt | cut -d'' -f6 but i don’t work . What I do wrong ?

This include info.txt :

JavaScript

and I want to get this :

JavaScript

Advertisement

Answer

most cuts count literal characters, so for -f 6 to work, your data has to be exactly in the same columns. Not sure if your 3rd to last line is a typo or an exact reproduction of your output, but it illustrates the problem with cut perfectly.

For this case, most people will use an awk solution:

JavaScript

Will produce the output you have listed

The beauty of awk is that field 6 is determined by the value of awk FS variable (field separator), which defaults to “multiple white space values” (space or tab) (this is not an exact description, but is close enough for your needs).

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement