Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7944737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:38:33+00:00 2026-06-04T00:38:33+00:00

How to extract whatever string comes after a matched pattern in Shell script. I

  • 0

How to extract whatever string comes after a matched pattern in Shell script. I know this functionality in Perl scripting, but i dont know in Shell scripting.

Following is the example,

Subject_01: This is a sample subject and this may vary

I have to extract whatever string that follows “Subject_01:”

Any help please.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T00:38:35+00:00Added an answer on June 4, 2026 at 12:38 am

    It depends on your shell.

    If you’re using bourne shell or bash or (I believe) pdksh, then you can do fancy stuff like this:

    $ string="Subject_01: This is a sample subject and this may vary"
    $ output="${string#*: }"
    $ echo $output
    This is a sample subject and this may vary
    $
    

    Note that this is pretty limited in terms of format. The line above requires that you have ONE space after your colon. If you have more, it will pad the beginning of $output.

    If you’re using some other shell, you may have to do something like this, with the cut command:

    > setenv string "Subject_01: This is a sample subject and this may vary"
    > setenv output "`echo '$string' | cut -d: -f2`"
    > echo $output
    This is a sample subject and this may vary
    > setenv output "`echo '$string' | sed 's/^[^:]*: *//'`"
    > echo $output
    This is a sample subject and this may vary
    > 
    

    The first example uses cut, which is very small and simple. The second example uses sed, which can do far more, but is a (very) little heavier in terms of CPU.

    YMMV. There’s probably a better way to handle this in csh (my second example uses tcsh), but I do most of my shell programming in Bourne.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Extract the number after #/ from my string: abcdefg#/123 .
I need to extract the command, whatever we see in ( ) after the
I want to extract the quoted substrings from inside a string. This is an
I have urls such as /blah/WHATEVER/sites/two/one/blah/need/this.ini in PHP, how do I extract /need/this.ini with
I've tried multiple functions to extract whatever between two strings, The delimiters might contain
I am attempting to extract all instances of a particular format from a string:
I'm trying to extract about 72000 SInt32s from the iPhone, but not sure what
I need to extract the xxxx in the following string in a url: {anything}/d/xxxx/{anything}
I'm trying to extract the domain name from a string in C#. You don't
I'm using BeautifulSoup to extract some text from an HTML but I just can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.