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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:32:10+00:00 2026-05-24T16:32:10+00:00

Script performs two things 1.Enables the user input a file name 2.Enables the user

  • 0

Script performs two things

1.Enables the user input a file name

2.Enables the user to input a line number to view the content

echo "Enter the file name"
read fname
  find / -name "$fname" > /tmp/newone.txt

if test $? -eq 0
then
 {
  echo "File found"
  echo "The no of line in the file $fname is `cat /tmp/newone.txt | wc|awk '{pri
nt $1}'`"
  echo  "Enter the line no"
  read  lcnt
  sed '"$lcnt" p' "$fname"
 }
else
 {
   echo "File not found"
 }
fi

Issue
1.Getting error in the sed part

Error message “sed: -e expression #1, char 3: extra characters after command”

how to rectify it ?

2.Can i redirect the output of ‘find’ to a variable

For example

$flloc =/tmp/newone.txt

so i will be able to use ‘$flloc’ instead of the absolute path

  • 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-05-24T16:32:12+00:00Added an answer on May 24, 2026 at 4:32 pm

    1) This is how you’d go about using your variable in the sed command:

    echo "Line no: "
    read lcnt
    
    sed -n "$lcnt p" $fname
    

    What was wrong with your original expression is that bash variables aren’t interpreted when you use single quotes. Example:

    lcnt=5
    
    # prints $lcnt
    echo '$lcnt'
    
    # prints 5
    echo "$lcnt"
    

    2) To store your find output to a variable, simply do this:

    floc=`find / -name $fname` # Here I'm using backticks, not single quotes.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The user should input two strings and the script will performe a text search:
I have a python script that, once executed from command line, performs the needed
I have a script in PHP which retrieves two very similar files and performs
I have an Ant script that performs a copy operation using the 'copy' task
Script: http://keith-wood.name/countdown.htm Daily json response: items: { fajr: '5:23 am', sharooq: '7:23 am', dhur:
I'd like to prevent multiple instances of the same long-running python command-line script from
I have two PHP scripts which both have an include_once('authentication.inc'); script near the top.
working on an ANT build file, where I have two macros defined and need
I'm trying to setup a search page which performs two separate kinds of search
I have two ASMX web services consumed from javascript. The first service performs a

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.