The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Career Guidance sufi_431 What's on Your Mind? 1 10-23-2007 11:54 AM
NIM Guidance scottsl AIX 1 06-12-2006 12:18 PM
Sed help needed stevefox Shell Programming and Scripting 5 12-05-2005 01:44 AM
Looking for guidance in obtaining a job in Unix Administration pkali290 SCO 4 12-09-2003 03:51 AM
select in ksh, any guidance for bash? Shakey21 UNIX for Dummies Questions & Answers 1 05-09-2002 01:40 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-07-2008
shadow0001 shadow0001 is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 10
A little guidance needed :)

Hi guys, I'm learning the ropes of BASH and am doing a few exercises to see if its sinking in but have gotten stuck on something I KNOW is looking at me right in the face but just isn't registering.

I'm creating a script that needs to get specific strings from a line. So using the "ls -l <filename>" command, i get a string with 6 fields (permissions and so forth). No i know there is a way to get an individual field from the 6 fields and store it but i just cant remember it. I believe its a pipe to the grep command but I'm unsure and for all i know there is an easier method.

Any help would be appreciated!

Code:

str = $(ls -l <filename>) #To get the info

now i just need to "split" the data - if it was perl, easy enough :P.

Edit: No AWK or SED.
  #2 (permalink)  
Old 03-07-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,322
Quote:
Originally Posted by shadow0001 View Post
Edit: No AWK or SED.
This sounds like a homework question, try:

Code:
man cut
Regards
  #3 (permalink)  
Old 03-07-2008
shadow0001 shadow0001 is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 10
Indeed you could call it something like that.. Still if I'm not going to get anywhere sitting around and fiddling about then i may as well ask. Otherwise im not learning anything .. just wasting a bit of time.

Cheers non the less!

Code

str=$(ls -l <filename> | cut -d ' ' -f 1)

-d Delimiter (space in my case)
-f fields (1st one in my case)

Just a brief explanation if someone was stuck on a similar situation.

Last edited by shadow0001; 03-07-2008 at 11:35 AM..
  #4 (permalink)  
Old 03-07-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,777
The default field separator is a space. -d will not break anything but it is not required.
  #5 (permalink)  
Old 03-07-2008
shadow0001 shadow0001 is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 10
I tried that however it did not work - brought up the entire line with out the option. Unix doesn't like me very much lol.

A final (i hope) question. If i had the work "command" and i wanted to split it into characters, how would i go about doing this ? See i need to be able to process each character individually using a loop however i am not aware of a command that allows me to do this.

Thanks again.
  #6 (permalink)  
Old 03-07-2008
miltonkeynesguy miltonkeynesguy is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 20
position=1

#put the following in a loop
#cut -c stands for column
while [ $position -ge 8 ]
do
echo `cut -c$position`
position=`expr $position + 1`
done
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:02 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0