Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Cut command: can't make it cut fields Post 302971706 by Don Cragun on Sunday 24th of April 2016 06:33:18 PM
Old 04-24-2016
If the idea is just to use tr to translate ls -l output spaces and tabs separating fields into single tab characters, you can try:
Code:
ls -l|tr -s '[:blank:]' '\t'|cut -f 1,3,4,9

which should do what you want as long as none of your filenames contain whitespace characters (i.e., spaces, tabs, or newlines). But, stat might be more reliable and just needs one command instead of a three stage pipeline:
Code:
stat -f '%Sp%t%Su%t%Sg%t%N' *

which should do what you want unless you have a lot of files in your directory with enough long filenames to overflow ARG_MAX limits.

And, if you could have large numbers of files some of which have names that contain space or tab characters (but not newlines) you could always feed the ls output through sed:
Code:
ls -l|sed 's/\([^[:blank:]]*\)[[:blank:]]*[0-9]*[[:blank:]]*\([^[:blank:]]*\)[[:blank:]]*\([^[:blank:]]*\)\([[:blank:]]*[^[:blank:]]*\)\{4\} /\1        \2      \3      /'

where those are literal tab characters after the \1, \2, and \3 in the replacement text of the substitute command to get exactly what you want no matter how many files are present in the directory.

Note that in all of these I used the blank character class instead of just using a space character in these patterns and BREs because I'm not sure whether ls ever uses tab characters to reduce the number of characters it writes while lining up output fields.
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to cut fields

I want to cut two coloums simulatiously and paste in some other file for ex: cut d ' ' -f3 -f4 xxx | paste yyy - > zzz; from the above i want to cut two fileds 3 and 4 and paste as last coloums of single file (zzz). how to solve this regards rajan (1 Reply)
Discussion started by: rajan_ka1
1 Replies

2. Shell Programming and Scripting

Cut Last 3 Fields

I have a text: dsj khfksjdh <time> EST 2006 ab cgnr jkkjt <time> EST 2006 gfhdgjghg <time> EST 2006 fkdjh kjhsekjrh kdjhfkh jhdfkhfdkjh kjdf <time> EST 2006 In the above file i need to extract time from every line... which is always the third from the last... Pls help! Cheers, Bouren (4 Replies)
Discussion started by: bourne
4 Replies

3. Shell Programming and Scripting

cut: get either one or two fields

Hello, I would like to extract one or two fields of a line. At the moment, I am extracting the first field of a line: command | cut -f 1 -d '.' > file The line can have two or three fields delimited with a dot. if three fields, I want to be able to get the first two ie if line =... (3 Replies)
Discussion started by: maxvirrozeito
3 Replies

4. Shell Programming and Scripting

awk sed cut? to rearrange random number of fields into 3 fields

I'm working on formatting some attendance data to meet a vendors requirements to upload to their system. With some help on the forums here, I have the data close. But they've since changed what they want. The vendor wants me to submit three fields to them. Field 1 is the studentid field,... (4 Replies)
Discussion started by: axo959
4 Replies

5. Shell Programming and Scripting

Cut Command error cut: Bad range

Hi Can anyone what I am doing wrong while using cut command. for f in *.log do logfilename=$f Log "Log file Name: $logfilename" logfile1=`basename $logfilename .log` flength=${#logfile1} Log "file length $flength" from_length=$(($flength - 15)) Log "from... (2 Replies)
Discussion started by: dgmm
2 Replies

6. Shell Programming and Scripting

How to make the cut command read a column after logical statements are meet?

Hi, I want to write a code that will cut everything that is under a couple of columns in a text file but so far I am not even close to achieve something like that. Basically, I want to cut all the information from the columns and transfer the column information to a spread sheet. I have... (1 Reply)
Discussion started by: pericopericone
1 Replies

7. UNIX for Dummies Questions & Answers

Cut pid from ps using cut command

hay i am trying to get JUST the PID from the ps command. my command line is: ps -ef | grep "mintty" | cut -d' ' -f2 but i get an empty line. i assume that the delimiter is not just one space character, but can't figure out what should i do in order to do that. i know i can use awk or cut... (8 Replies)
Discussion started by: ran ber
8 Replies

8. Shell Programming and Scripting

Need a separator string between fields in cut -c command

Hi All, I'm trying to view data using cut command for a fixed length file using the below command: cut -c 1-3,4-5 FALCON_PIS_00000000.dat I want to mention a separator say | (pipe) in between 1-3 and 4-5. Please let me know how to achieve this. Thanks in Advance, (3 Replies)
Discussion started by: HemaV
3 Replies

9. Shell Programming and Scripting

How To Count Fields For Cut?

I am new to cut and I want to use the field option with a space delimiter on an Apache log file. For example, if I wanted to find the 200 HTTP code using cut in this manner on the file below cat access_abc.log | cut -d' ' -f7 | grep "200" 157.55.39.183 - - "GET /content/696-news041305... (4 Replies)
Discussion started by: sharingsunshine
4 Replies
ISWBLANK(3)						     Linux Programmer's Manual						       ISWBLANK(3)

NAME
iswblank - test for whitespace wide character SYNOPSIS
#include <wctype.h> int iswblank(wint_t wc); DESCRIPTION
The iswblank function is the wide-character equivalent of the isblank function. It tests whether wc is a wide character belonging to the wide character class "blank". The wide character class "blank" is a subclass of the wide character class "space". Being a subclass of the wide character class "space", the wide character class "blank" is disjoint from the wide character class "graph" and therefore also disjoint from its subclasses "alnum", "alpha", "upper", "lower", "digit", "xdigit", "punct". The wide character class "blank" always contains at least the space character and the control character ' '. RETURN VALUE
The iswblank function returns non-zero if wc is a wide character belonging to the wide character class "blank". Otherwise it returns zero. CONFORMING TO
This function is a GNU extension. SEE ALSO
isblank(3), iswctype(3) NOTES
The behaviour of iswblank depends on the LC_CTYPE category of the current locale. GNU
1999-07-25 ISWBLANK(3)
All times are GMT -4. The time now is 02:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy