LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-02-2014, 10:14 PM   #16
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,244

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684

Ok ... it seems we jumped the gun.

Try reading something like http://tldp.org/LDP/abs/html/

Specifically look for #,## and %,%% and also ${#variable_name}:
Code:
var='one two three four'

f_pos="${var%f*}f"

len=${#f_pos}

echo $len
This would show you which position the letter 'f' is at in the original string
 
Old 12-02-2014, 10:28 PM   #17
jeffrey1289
LQ Newbie
 
Registered: Dec 2014
Posts: 10

Original Poster
Rep: Reputation: Disabled
I don't have a textbook....
 
Old 12-02-2014, 11:24 PM   #18
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,244

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
So you are doing a course and there is no textbook, course notes or online material provided ... how very strange. In this case I would probably suggest changing to a course / school where it is reputable and actually
provides the material required for learning.
 
1 members found this post helpful.
Old 12-03-2014, 05:02 PM   #19
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 2,959

Rep: Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268
I agree it doesn't seem like a very well organized course, and your code samples to date seem to indicate that you've just jumped into the deep end of the pool, e.g.:
Quote:
Originally Posted by jeffrey1289 View Post
Code:
 
    if length "$line" | grep '^[^;]' > max
      max=length "$line" | grep '^[^;]'
That is so far removed from any syntax I know that I can't even tell what language it's supposed to be.

Just some useful hints:
Code:
Matcher="^([^;].*[^ ]) *(;.*)"     # A regular expression to match a string beginning with something other
                                   #   than a semicolon, followed by a string of any characters up through
                                   #   the last non-space character that is then followed by any spaces and
                                   #   a semicolon then followed by any number of characters.  (Whew!)
if [[ $Line =~ $Matcher ]]; then   # If line contains both code and comment
    Code="${BASH_REMATCH[1]}"      # First parenthesized segment is just the code w/o trailing spaces
    Comment="${BASH_REMATCH[2]}"   # Second parenthesized segment is the comment
    Code_length=${#Code}           # Length of $Code
    .
    .
    .
fi
 
  


Reply

Tags
code


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




All times are GMT -5. The time now is 01:53 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration