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

  • Home
  • SEARCH
  • 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 9099391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:36:15+00:00 2026-06-17T00:36:15+00:00

I have a text file called db.txt. Some sample lines from the file goes

  • 0

I have a text file called db.txt.
Some sample lines from the file goes as such:

Harry Potter and the Sorcerer’s Stone:J.K. Rowling:21.95:100:200

Harry Potter and the Chamber of Secrets:J.K. Rowling:21.95:150:300

Lord of the Rings, The Fellowship of the Ring:J.R.R. Tolkien:32.00:500:500

A Game of Thrones:George R.R. Martin:44.50:300:250

Then in my script, I have the following lines:

echo "Enter title:"
read TITLE

cut -d ":" -f 1 db.txt | grep -iw "$TITLE" | while read LINE
do
    STRING="`echo $LINE | cut -d ":" -f 1`,"
    STRING="$STRING `echo $LINE | cut -d ":" -f 2`, "
    STRING=" \$$STRING`echo $LINE | cut -d ":" -f 3`,"
    STRING=" $STRING`echo $LINE | cut -d ":" -f 4`,"
    STRING=" $STRING`echo $LINE | cut -d ":" -f 5`"
done

Is there a way to grep a specific field from cut and then pass in the full line into the while loop?

For example, if I entered "Harry Potter",
it should display:

Harry Potter and the Sorcerer’s Stone, J.K. Rowling, $21.95, 100, 200

Harry Potter and the Chamber of Secrets, J.K. Rowling, $21.95, 150, 300

  • 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-17T00:36:17+00:00Added an answer on June 17, 2026 at 12:36 am

    You can do this without cut, and without grep if you’re ok with bash’s regular expression matching (or can use shell pattern matching instead).

    The idea would be to read the file line by line, then split the line into an array.
    Once you’ve got that, do the comparisons and output you want.

    Here’s a demo of the technique:

    #! /bin/bash
    echo "Title:"
    read title
    
    # shopt -s nocasematch           # if you want case-insensitive matching
    
    while read line ; do             # this read takes data from input.txt, see
                                     # end of loop
            IFS=: read -a parts <<< "$line"  # this splits the line on ":" into
                                             # an array called parts
    
            if [[ ${parts[0]} =~ $title ]] ; then  # regex matching
                    printf "%s -- %s\n" "${parts[1]}" "${parts[2]}"
            fi
    done < input.txt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file called text.txt that contains: <li id=unic1>some text</li> <li id=unic2>some text</li>
I have a file (called print_1012720.txt ) that looks like the text shown below.
So I have the following code to check for the text file called Doctors.txt
I have a list of files stored in a text file called tempfile.txt. eg
So I have a text file called maze.txt that looks like this: ############### Sacbifnsdfweovw
I have text file with some stuff that i would like to put into
I have text file with some text information and i need to split this
I have text file. there around 1000 lines in it, each line contains a
Let's say I have a file called test.txt within the package com.test.io within my
I have some jQuery code. I have called an Ajax function file, file.php, that

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.