Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cut command

Status
Not open for further replies.

asafbu

IS-IT--Management
Aug 1, 2007
3
US
Hello,

I'm trying to use cut command to retrieve timestamp from a list of files in a certain folder. It seems that cut command mesing up with the spaces

fileTimestamp="`ls -l ${BASE_DIR}/some_dir/${fileName}`" --I
somevar="`echo $fileTimestamp | cut -c 1-40`" ---II

The results of the (II) does not preserve spaces:

-rw-rw-rw- 1 d13ukas vzwadmin 4706 Aug 1
-rw-rw-r-- 1 d13ukas vzwadmin 155365 Aug
-rw-rw-r-- 1 d13ukas vzwadmin 77765 Aug
-rw-rw-r-- 1 d13ukas vzwadmin 489210 Aug

Results of (I) are just fine.
Any ideas?

Thanks
 
Why not simply this ?
somevar="`ls -l ${BASE_DIR}/some_dir/${fileName} | cut -c 1-40`"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks for the reply!

because the variable in I is used other places. So, you think it is happening because I'm storing the results in a variable?

 
No, it is prbably happening because you use the echo command without quoting its parameters ?
What happens if, with your posted code, you type this ?
echo [!]"[/!]$somevar[!]"[/!]

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
OOps, the loosing of space is here:
somevar="`[!]echo $fileTimestamp[/!] | cut -c 1-40`"
What about this ?
somevar=`echo "$fileTimestamp" | cut -c 1-40`

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I think you nailed it!

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top