A little guidance needed :)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting A little guidance needed :)
# 1  
Old 03-07-2008
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  
Old 03-07-2008
Quote:
Originally Posted by shadow0001
Edit: No AWK or SED.
This sounds like a homework question, try:

Code:
man cut

Regards
# 3  
Old 03-07-2008
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  
Old 03-07-2008
The default field separator is a space. -d will not break anything but it is not required.
# 5  
Old 03-07-2008
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  
Old 03-07-2008
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
# 7  
Old 03-07-2008
position=1
word="command"
#put the following in a loop
#cut -c stands for column
while [ $position -ge 8 ]
do
echo `echo $word |cut -c$position`
position=`expr $position + 1`
done
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

New to AIX. Need Guidance

Hi There, I am new to AIX. I am eager to learn the AIX System administration or if there is any other prerequisite before this. Please can anyone help me or guide how to start with AIX, what all courses and certifications do I need to do. I have basic knowledge of UNIX. Please guide as I am... (3 Replies)
Discussion started by: rahulat302
3 Replies

2. Shell Programming and Scripting

Need Some guidance on scripting

Hey All, I am newbie on scripting and need some guidance from all the experts here. I am working on one project where I will check the status/health of around ten (10) solaris 10 servers. I have one central server from where I have already setup the passwordless SFTP and setup the cron... (1 Reply)
Discussion started by: supercops
1 Replies

3. UNIX for Dummies Questions & Answers

Just need some guidance on this nawk

Hi, I am trying to debug some KSH script and it has the nawk portion below. I just want to confirm whether I understand what it does correctly. Example usage of the nawk line is run as below: nawk '/^#/ {next} $1~/^'testp.cfg'$|^'testp.cfg'\.testdb\.com\.ph$/ { c=0 while... (1 Reply)
Discussion started by: newbie_01
1 Replies

4. AIX

Need guidance on VMStat

I need some guidance on the differences in observations, not sure how significantly different are they. Also, It would be nice to hear on the values and what the obvious tuning for performance missing. Observation 1 ending vmstat -v 3948544 memory pages ending vmstat -v ... (1 Reply)
Discussion started by: Snipper
1 Replies

5. Shell Programming and Scripting

Guidance needed for a typical shell script with sql query

Hi , I have a txt file with contents like: 1234 2345 3456 7891 I need to write a script which takes input file as txt file..run a sql query for that number and place the output of query in another file.. select * from bus_event where acct_nbr='1234'( from input txt file) the query... (20 Replies)
Discussion started by: Rajesh Putnala
20 Replies

6. UNIX for Dummies Questions & Answers

Need guidance on RHEL patch

Hi, I am new with updates in RHEL especially servers. The question is: 1. Do I need to register to RHEL in order for me to use the up2date? 2. For updates in RHEL need to use up2date, but what is the thing that I need to do before the patches? I mean what should I backup in case my patches... (0 Replies)
Discussion started by: flekzout
0 Replies

7. HP-UX

HP-UX 10.20 fbackup? restore help/guidance needed

Hello, We've recently had a multiple hardrive failure in our legacy HP9000. Now the drives are repaired and the filesystems are recreated, I went to restore the last of the database tables from our dds3 backup, but cannot. Here's what's going on: BTW, I'm an absolute novice w/ HP-UX The... (5 Replies)
Discussion started by: jastuart
5 Replies

8. UNIX for Advanced & Expert Users

Guidance needed for quick script

Hi all, I am trying to get the exception count daily from a log file which is more than 1 GB in size. I am using loops which get the count of the exception and transaction. But i need to take this exception count for a time frame from 5.00 am to 5:00 pm. I Think I can use to exact the... (4 Replies)
Discussion started by: senthilkumar_ak
4 Replies

9. What is on Your Mind?

Career Guidance

Hi, I am a newbie to Unix, I was introduced to UNIX 8 months back during my Training, I was attracted to Unix as they give complete freedom. I would like to ask how can a OS Admin can go into development field of Unix. Currently I am working in a MNC in Backup- Storage Admin Domain I am... (1 Reply)
Discussion started by: sufi_431
1 Replies

10. AIX

NIM Guidance

I've just started to explore NIM and I'm looking for additional information on how to set it up and configure it. I've read through the "NIM A-Z" and have many unanswered questions. One question is how can I have the NIM server pull a mksysb of the clients and can I schedule this to happen... (1 Reply)
Discussion started by: scottsl
1 Replies
Login or Register to Ask a Question