Find the answer to your Linux question:
Results 1 to 6 of 6
Hi all, I am new to linux scripting, I want normal substring of a string that actually is a url as follows SITEURL/main.php?page=122&type=download_file&fileID=9&user Id=user1&org=org1&mainmenu=main1&submenu=sub1 What I want is a substring ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Sep 2010
    Posts
    7

    Unhappy Getting substring of String


    Hi all,

    I am new to linux scripting, I want normal substring of a string that actually is a url as follows

    SITEURL/main.php?page=122&type=download_file&fileID=9&user Id=user1&org=org1&mainmenu=main1&submenu=sub1

    What I want is a substring like below

    org1_user1_main1_sub1

    Please help me solve the problem

    Thanks in advance

  2. #2
    Linux User Manko10's Avatar
    Join Date
    Sep 2010
    Posts
    250
    Which programming language do you use? C/C++? Python? Bourne Shell? C Shell? Perl? PHP?

  3. #3
    Just Joined!
    Join Date
    Sep 2010
    Posts
    7
    Thnx for you quick response.
    I have to use linux shell script.

  4. #4
    Linux User Manko10's Avatar
    Join Date
    Sep 2010
    Posts
    250
    So I assume you use Bourne/Bash scripting language.
    I suggest you to learn one thing or two about string manipulation in shell scripts. You may find good resources about this topic a lot, but here is one: Advanced Bash Shell Scripting Guide - Manipulating Strings
    This tutorial uses expr for performing regexp operations but you can also use tools like grep or sed

  5. #5
    Just Joined!
    Join Date
    Sep 2010
    Posts
    7

    Unhappy

    Thnx for you help ..
    but I am totally new to shell script programming ...
    If you can mention some code.. it can help a lot

    THanks again..

  6. #6
    Linux User
    Join Date
    Nov 2009
    Location
    France
    Posts
    292
    Code:
    s="SITEURL/main.php?page=122&type=download_file&fileID=9&user_Id=user1&org=org1&mainmenu=main1&submenu=sub1"
    echo $s | awk -F "&" '{print $4}' | awk -F "=" '{print $2}'
    This outputs user1. You can loop through the second line to get the next fields, store in variables and concatenate at will.
    0 + 1 = 1 != 2 <> 3 != 4 ...
    Until the camel can pass though the eye of the needle.

Posting Permissions

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