![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| assigning variables from standard output | whamchaxed | UNIX for Dummies Questions & Answers | 2 | 12-04-2007 03:31 PM |
| assigning variables in sed command | wxornot | Shell Programming and Scripting | 3 | 02-04-2006 10:56 AM |
| Problem in assigning values to variables | mohanprabu | Shell Programming and Scripting | 3 | 08-25-2005 01:44 AM |
| Assigning nawk output to variables | steveje0711 | Shell Programming and Scripting | 6 | 08-19-2005 02:03 PM |
| assigning variables | k@ssidy | UNIX for Dummies Questions & Answers | 9 | 06-16-2005 07:20 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
Assigning file attributes to variables
Hi,
I'm trying to assign the permissions, owner and group of a file to seperate variables, but using ls -l filename | awk '{print $1 "\t" $3 "\t" $4}' gives the owner as tom.ja instead of tom.james Is there any way to expand it so i get the full name, or is there an easier way to get them into variables? Also, i'm processing the permissions into a table ie Owner has READ and EXECUTE permissions, Group has... etc. I was thinking to use a shift to deal with each permission, is there any way to now seperate each permission? ie. -rwxr-x-r-- into - r w x r - x - r - - it doesn't have to be whitespace, but just so i can process each one. Thanks Oliver |
| Forum Sponsor | ||
|
|
|
|||
|
Dear Oliver,
I am not sure about your first problem as it's working fine on my machine as far as tour second problem is concern, you can try this code. ls -ltr filename | awk '{ for (i=1;i<10;i++) print(substr($1,i,1)); }' regards Apoorva kumar |
|
||||
|
Another way to parse file attributes :
Code:
ls -l x.sh | read perms links owner group size mtime1 mtime2 mtime3 file echo "$perms | $links | $owner | $group | $size | $mtime1 $mtime2 $mtime3 | $file" Quote:
Last edited by aigles; 08-18-2006 at 06:37 AM. Reason: Correct variable name and display |
|
|||
|
Thanks for the advice
Thanks Apoorva, this works great! As for the first question, if the owner name isn't cut short with you, maybe the columns are too small on mine, is there any way to widen them so i get the full username? Dhruva, could you explain what f1, f3 and f4 do? As when i tried your code the only output is from $perm which is -rwxr-xr-x And i'm afraid John-Pierre that yours only prints out the | !! Thanks again for your help, Oliver |
|
|||
|
Dear Oliver,
I have not faced any colmn size problem so far. Still if you think so, you can also try 'printf' function. As far as f1,f2...are concern they just indecate the respective fields. regards Apoorva Kumar |
|||
| Google The UNIX and Linux Forums |