Space as a delimiter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Space as a delimiter
# 1  
Old 12-08-2010
Space as a delimiter

not sure if i'm doing this right i'm new tho this but i'm trying to use a space as a delimiter with the cut command

my code is

size=$( du -k -S -s /home/cmik | cut -d' ' -f1 )

i've also tried -f2 and switching the -d and -f around if that does anything
# 2  
Old 12-08-2010
I see that above command prints the whole record (size and directory name). Not sure why it's not able to print only the size.
But following should work.
Code:
size=$( echo $(du -k -S -s /home/cmik) | cut -d' ' -f1 )

OR
Code:
size=$( du -k -S -s /home/cmik | cut -f1 )

OR
Code:
size=$( du -k -S -s /home/cmik | awk '{print $1}' )

OR
Code:
size=$( du -k -S -s /home/cmik | awk -F " " '{print $1}' )


Last edited by anurag.singh; 12-08-2010 at 09:26 PM..
# 3  
Old 12-08-2010
I think du uses a TAB character between the size and the name so no -d needed on cut

Code:
size=$( du -k -S -s /home/cmik | cut -f1 )

# 4  
Old 12-08-2010
Smilie thank that worked
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

AIX sed use space as delimiter

I am trying to do this with one small tweak. I would also like to use a space as a delimiter. sed 's/ */\ /g' file This is what my file looks like. server1, server2, server3 server4 server5 server6 I would like it to look like this. server1 server2 server3 server4 ... (6 Replies)
Discussion started by: cokedude
6 Replies

2. Shell Programming and Scripting

Perl Code to change file delimiter (passed as argument) to bar delimiter

Hi, Extremely new to Perl scripting, but need a quick fix without using TEXT::CSV I need to read in a file, pass any delimiter as an argument, and convert it to bar delimited on the output. In addition, enclose fields within double quotes in case of any embedded delimiters. Any help would... (2 Replies)
Discussion started by: JPB1977
2 Replies

3. Shell Programming and Scripting

Need to use delimiter as : and space in awk

Hi , Please suggest me how do I use : (colon and one space) as a delimiter in awk Best regards, Vishal (2 Replies)
Discussion started by: Vishal_dba
2 Replies

4. Shell Programming and Scripting

Need next line as a space delimiter in awk

Hi,Below is the output for p3fi_dev services 1/app/oracle> . ./oraprofile_p3fi_dev p3fi_dev_01 (P):/devoragridcn_01/app/oracle> srvctl config service -d p3fi_dev p3fi_p3fi_dev.world PREF: p3fi_dev_01 AVAIL: p3fi_dev_02 pplnet_p3fidev PREF: p3fi_dev_01 AVAIL: p3fi_dev_02 nexus_p3fidev PREF:... (3 Replies)
Discussion started by: Vishal_dba
3 Replies

5. Shell Programming and Scripting

Problem in extraction when space is a field delimiter

I have more than 1000 files to parse. Each file contains few lines (number of lines varies) followed by a header line having all column's name (SPOT, NAME etc) and then values for those columns. **Example File: sdgafh dfhaadfha sfgaf dhah jkthdj SPOT NAME GENE_NAME CH_MEAN CHDN_MED ... (11 Replies)
Discussion started by: AshwaniSharma09
11 Replies

6. Shell Programming and Scripting

comma delimiter and space

I have a csv file and there is a problem which I need to resolve. Column1,Column2,Colum3,Column4 ,x,y,z ,d,c,v t,l,m,n ,h,s,k ,k,,y z,j, ,p Now if you see column1 for row 1 and row 4 though they are null there is a space but in case of row2 and row 5 there is no space. I want row... (3 Replies)
Discussion started by: RubinPat
3 Replies

7. UNIX for Dummies Questions & Answers

Delimiter: Tab or Space?

Hello, Is there a direct command to check if the delimiter in your file is a tab or a space? And how can they be converted from one to another. Thanks, G (4 Replies)
Discussion started by: Gussifinknottle
4 Replies

8. UNIX for Dummies Questions & Answers

Problem Using Cut With A Space Delimiter

I am trying to extract 'postmaster' from the following string: PenaltyError:=554 5.7.1 Error, send your mail to postmaster@LOCALDOMAIN using the following command: cat /usr/share/assp/assp.cfg | grep ^PenaltyError:= | cut -d '@' -f1 | cut -f8 but it returns: PenaltyError:=554 5.7.1 Error,... (10 Replies)
Discussion started by: cleanden
10 Replies

9. UNIX for Dummies Questions & Answers

replacing space with pipe(delimiter)

Hello All, I have a file with thousands of records: eg: |000222|123456987|||||||AARONSON| JOHN P|||PRIMARY |P |000111|567894521|||||||ATHENS| WILLIAM k|||AAAA|L Expected: |000222|123456987|||||||AARONSON| JOHN |P|||PRIMARY |P |000111|567894521|||||||ATHENS| WILLIAM |k|||AAAA|L I... (6 Replies)
Discussion started by: OSD
6 Replies

10. Shell Programming and Scripting

replace space with delimiter in whole file -perl

Hi I have a file which have say about 100,000 records.. the records in it look like Some kind of text 1234567891 abcd February 14, 2008 03:58:54 AM lmnop This is how it looks.. if u notice there is a 2byte space between each column.. and im planning to replace that with '|' .. ... (11 Replies)
Discussion started by: meghana
11 Replies
Login or Register to Ask a Question