![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 's | manas6 | UNIX for Dummies Questions & Answers | 0 | 06-05-2008 03:44 AM |
| extracting fields | prvnrk | Shell Programming and Scripting | 2 | 10-08-2007 12:39 AM |
| extracting a string | start_shell | Shell Programming and Scripting | 2 | 09-30-2007 05:41 AM |
| Extracting a users environment variables | Tornado | Shell Programming and Scripting | 2 | 12-04-2006 11:23 PM |
| extracting from tar.bz2 | Raom | UNIX for Advanced & Expert Users | 1 | 03-07-2006 07:33 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
extracting return of ls -l into variables
If I do "ls -l filename" in a script, it should return something like this:
-rw-r--r-- 1 user group 5945 Feb 28 14:24 filename How do I put each of the above strings into a different variable? eg Permissions, username, groupname, date |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
something like this,
Code:
ls -l filename | awk '{print $1, $3, $4, $6"-"$7"-"$8}' | read perm username grpname date
|
|
#3
|
|||
|
|||
|
Excellent. Thanks a lot!
|
|
#4
|
|||
|
|||
|
Okay, I've been playing around with the command you gave me, matrixmadhan, but I can't figure out how to print the fields $1, $2, $3 etc to different variables. They always either end up in the first variable, or all the variables remain blank. Any ideas?
|
|
#5
|
||||
|
||||
|
That command will only work if your shell is ksh.
|
|
#6
|
|||
|
|||
|
Right. I'm in a bash shell. Any ideas about how I go about it in that?
|
|
#7
|
||||
|
||||
|
You can set named variables like $perm $username etc by using something like this....
Code:
eval $(ls -l file1|awk '{printf "perm=%s username=%s", $1, $3}')
Code:
set -- $(ls -l file1) perm=$1 username=$3 Last edited by Ygor; 03-01-2006 at 10:29 PM. |
||||
| Google The UNIX and Linux Forums |