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 8643335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:00:38+00:00 2026-06-12T12:00:38+00:00

Say I have the following file names from an ls in a bash script:

  • 0

Say I have the following file names from an ls in a bash script:

things-hd-91-Statistics.db
things.things_domain_idx-hd-38-Data.db

In bash, how would it be able to get the first part of the string 'things' in either case?
Basically remove the rest of the string past the first - or .

  • 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-12T12:00:40+00:00Added an answer on June 12, 2026 at 12:00 pm

    You would use parameter expansion:

    string="things-hd-91-Statistics.db"
    echo "${string%%-*}"
    things

    Where in ${parameter%%pattern} the ‘pattern’ (-*) is matched against the end of ‘parameter’. The result is the expanded value of ‘parameter’ with the longest match deleted.

    Similarly for your other example, the pattern would be %%.*

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

Sidebar

Related Questions

Let's say we get the following data from a CSV file: account_number balance customer
I have the following code snippet, which loads data from a CSV file into
In a web project using jsp, I have following requirement Upload a file (say
Say I have the following data IEnumerable<IEnumerable<int>> items = new IEnumerable<int>[] { new int[]
I have a list of file names(I already have the filelist let's say in
I'm trying to accomplish the following: Have a thread that reads data from a
Say I have an XML file like the following: <holidays> <holiday1 val=New Years, 01/01,
i have the following situation : with my function i get an XML file
Say I have a regular expression like the following, but I loaded it from
Say I have a database table like the following: FileID | FileName | FileSize

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.