Aiskya
Aiskya

Reputation: 73

Having trouble creating and saving a text file in shell scriptin

I attempt to save a few lines into an output file called Temporal_regions.txt in my folder, so I can continue with further process.

I took a look at some of other post, and they suggested to do this way:

echo "some file content" > /path/to/outputfile

So my returned output looks like this:

1 3 13579 586 Right-Temporal 72 73 66 54

2 5 24680 587 Left-Temporal 89 44 65 56    

3 7 34552 599 Right-Temporal 72 75 66 54

4 8 24451 480 Left-Temporal 68 57  47 66

*All of these lines were individually returned as output using the grep command from another file (call it TR.stats)

If I want to store these outputs into the .txt (call it TemperolRegion.txt), I would have to first create the output file right? What would be the command to do this? Then, I can just simply use the above suggested way to store to the .txt file?

grep "Left-Temporal" TR.stats > /path/to/TemperolRegion.txt

I can't seem to get the commands right.

Upvotes: 0

Views: 43

Answers (1)

merlin2011
merlin2011

Reputation: 75545

It sounds like you are missing the directories along the path. In Linux, you have to create the parent directory before you create the file. You can create every directory along the path to the parent by using mkdir with the -p option.

mkdir -p /path/to
grep "Left-Temporal" TR.stats > /path/to/TemperolRegion.txt

Another problem you might have is that you are not in the right directory to TR.stats. In that case you should use the absolute path for that file as well.

grep "Left-Temporal" /path/to/TR.stats > /path/to/TemperolRegion.txt

Upvotes: 1

Related Questions