0

It has been long time since my last bash script. I m just trying to extract the content of a file from the the start variable to the stop one. My source file is night4.info and it contains a list of .jpg files.The structure of this file is similar to:

./2014-11-02/18h/00mn/2014-11-02T18-00-00.048000-depth.jpg
./2014-11-02/18h/00mn/2014-11-02T18-00-00.182000-depth.jpg
./2014-11-02/18h/00mn/2014-11-02T18-00-00.316000-depth.jpg

This is the code so far :

#! /bin/bash
start=$(grep -n $1 night4.info | cut -d : -f 1)  
stop=$(grep -n  $2 night4.info  | cut -d : -f 1)
echo "1" >> list.info
sed -n -e "$start,$stop p" night4.info >> list.info

And this is how I m running my script:

./script1.sh 2014-11-02T18-00-00.048000 2014-11-03T06-59-59.981000

There is no error message and the code doesn't give the right output.

2
  • 3
    What is your source file? and what is that you are trying to extract? Without the actual file, question is pointless Commented Jul 18, 2016 at 14:18
  • You can improve this question by trying to isolate the problem. Instead of pasting four lines and stating that it doesn't give the right output, find the smallest piece of code that doesn't do what you expect and show it along with input, expected output and actual output. See the bash tag wiki for an example of how to turn a bad script into a good question Commented Jul 18, 2016 at 14:37

1 Answer 1

1

You could use a Perl one-liner with the range operator:

perl -ne "print if /\Q$1\E/../\Q$2\E/" night4.info >> list.info
Sign up to request clarification or add additional context in comments.

2 Comments

What is this supposed to do? It appears to just print everything
It is working. But it will be better for me if I can fix my bash script. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.