Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 09-14-2001, 02:45 AM   #1
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.

Old 09-16-2001, 10:20 PM   #2
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,823

Rep: Reputation: 120Reputation: 120
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.
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
Registered: Sep 2001
Location: Cherry Hill, NJ
Distribution: Gentoo baby!
Posts: 67

Original Poster
Rep: Reputation: 15

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



Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

All times are GMT -5. The time now is 11:08 AM.

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