LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-14-2001, 02:45 AM   #1
elconde
Member
 
Registered: Sep 2001
Location: Cherry Hill, NJ
Distribution: Gentoo baby!
Posts: 67

Rep: Reputation: 15
Angry Simple C Shell script is not so simple


Imagine the following program in C Shell. What should I put in place of the question marks to assign the variables a, b, c, d or any other variables like them that may show up to the last number after the last backslash.


set a = "a/b/c/d/1/2/3"
set b = "e/r/r/4"
set c = "dew/gr/34/op3/22"
set d = "33/22/11/1?"
.
.
.

??????????????????????


So, I want to set the variables a, b, c, d to 3, 4, 22, and 1?. I tried using awk, but it was a disaster.

HELP!!!
 
Old 09-16-2001, 10:20 PM   #2
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
I would use bourne shell, C shell stinks when writing scripts. Use awk to find the number of slashes in the line, then use cut to cut out the last field. You will need to set the field seperator for awk. I tried it quickly here and awk didn't like the '/' as a delimiter. You can probably hack at it a bit to make it work.
Code:
FIELDS=`echo $A | awk ' { FS = "/"; print NF } '`
LAST=`echo $A | cut -d'/' -f$FIELDS`
This does not work, but I hope it will get you started.
 
Old 09-16-2001, 11:53 PM   #3
elconde
Member
 
Registered: Sep 2001
Location: Cherry Hill, NJ
Distribution: Gentoo baby!
Posts: 67

Original Poster
Rep: Reputation: 15
thanks

Thanks for the advice. I'll try it out.


-Robert
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple Shell Script Help Kristijan Programming 3 06-13-2005 09:13 PM
Simple shell script mikz Linux - General 1 02-24-2005 07:18 AM
simple shell script sharpie Programming 9 06-02-2004 11:47 PM
simple shell script Greg_courageous Programming 2 05-12-2004 04:34 PM
Very Simple Shell Script cli_man Linux - Software 5 04-24-2003 10:14 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:54 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration