Find the answer to your Linux question:
Results 1 to 8 of 8
I need to modify the input entered by a user into a very specific format. I'm able to read the input, but I can't see how you can add to ...
  1. #1
    Just Joined!
    Join Date
    Aug 2008
    Posts
    5

    Modifying user input

    I need to modify the input entered by a user into a very specific format. I'm able to read the input, but I can't see how you can add to it, or modify what they've keyed.

    For example, I need to change the format of an HBA world wide id address from the users input of 100000c812f4f0c1 to 10.00.00.c8.12.f4.f0.c1 any ideas?

  2. #2
    Linux Newbie
    Join Date
    Jul 2008
    Posts
    181
    You can't seriously expect a helpful answer to a question that vague. Don't you think it might be relevant to mention the programming language you are using and how you are getting the user input in the first place?

  3. #3
    Just Joined!
    Join Date
    Aug 2008
    Posts
    5
    burschik,

    Sorry about overlooking the obvious...

    In a nutshell, I am writing a bash script that prompts an operator for the wwid address of the hba card(s) in their server. I'll need to modify their reply by changing the format, for example - 100000c812f4f0c1 to 10.00.00.c8.12.f4.f0.c1

    Once I change the format, the script will add their server to the storage array (that will only acept the wwid address in this format).

  4. #4
    Linux Newbie
    Join Date
    Jul 2008
    Posts
    181
    Code:
    read input
    echo $input | sed 's/../&./g'

  5. #5
    Just Joined!
    Join Date
    Aug 2008
    Posts
    5
    Burschik,

    Worked like a champ. Thanks very, very much!

  6. #6
    Just Joined!
    Join Date
    Aug 2008
    Posts
    5
    Burschik,

    One last follow-up, the code returns an extra "." at the end of the string, how can I chop this off? From 10.00.00.00.c8.13.b2.1a. to 10.00.00.00.c8.13.b2.1a

  7. #7
    Linux Newbie
    Join Date
    Jul 2008
    Posts
    181
    Code:
    read input
    echo $input | sed 's/../&./g; s/\.$//'

  8. #8
    Just Joined!
    Join Date
    Aug 2008
    Posts
    5
    Thanks again, work perfectly!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...