How to extract file contents in UNIX

January 29, 2011 at 01:21:44
Specs: Unix
Problem:
I need to extract the contents of a file and then save/store it in a variable and then display the contents of the variable.

Question:
How can I extract the contents of a file if my file contains something like this:
- /home/myFolder/*.txt

EXAMPLE:
FILE: line.txt
CONTENTS: /home/myFolder/*.txt

When I run the code below, the result was, it displays all files in /home/myFolder directory that are ending in .txt.
CODE START:
$ a=`cat line.txt`
$ echo $a
CODE END:

My target is, when I run the code above, it will display only the content of line.txt.
- It should display this string: /home/myFolder/*.txt

Anyone knows how to do this?

Thanks in advance.


See More: How to extract file contents in UNIX

Report •

#1
January 29, 2011 at 04:18:29
Remove the dollar signs at the start of your two lines of code. Surround the $a with double quotes. So:

a=`cat line.txt`
echo "$a"


Report •
Related Solutions


Ask Question