LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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, 09:14 PM   #16
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,006

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191

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, 09: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, 10:24 PM   #18
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,006

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
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, 04:02 PM   #19
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,776

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
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



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



LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:49 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