Printing a file within a cat call


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Printing a file within a cat call
# 1  
Old 06-05-2013
Printing a file within a cat call

Hello,
I have a file called geom.txt which has some data in a particular format readable by another program (after adding some 'standard lines'), so what I want to do is to have a script that enables me to create a file (lets call it 'inpfile') readable for that program using a cat command, if I want to introduce the value of a previously defined variable (lets say key=345298) into 'inpfile' I simple type $key and it prints the value of the variable into the file, but how to print the content of geom.txt? This is what I have so far:
Code:
cat<<eoi>inpfile
Some standard lines of the program that is going to execute inpfile ....
$key
Content of geom.txt desired
Some other standard lines...
eoi

Thanks,
# 2  
Old 06-05-2013
Quote:
Originally Posted by jaldo0805
Hello,
I have a file called geom.txt which has some data in a particular format readable by another program (after adding some 'standard lines'), so what I want to do is to have a script that enables me to create a file (lets call it 'inpfile') readable for that program using a cat command, if I want to introduce the value of a previously defined variable (lets say key=345298) into 'inpfile' I simple type $key and it prints the value of the variable into the file, but how to print the content of geom.txt? This is what I have so far:
Code:
cat<<eoi>inpfile
Some standard lines of the program that is going to execute inpfile ....
$key
Content of geom.txt desired
Some other standard lines...
eoi

Thanks,
You're almost there. All you need to do is define key before you invoke cat. So for your example, all you need is:
Code:
key=345298
cat<<eoi>inpfile
Some standard lines of the program that is going to execute inpfile ....
$key
Content of geom.txt desired
Some other standard lines...
eoi

# 3  
Old 06-05-2013
Thanks for your reply, but probably I didn't express my question adequately... with the example using $key, I meant that if its only a variable previously defined what I want to print within the cat call, there is no problem, but if its the content of a file like geom.txt what I want to print within, it doesn't work the same way, that is by using $geom.txt it does not print the content of geom.txt... so in the "code example" I provided, in the line just after $key, what I really want is the actual content of geom.txt (which is a file that already exists in my working directory).
Thanks again,
# 4  
Old 06-05-2013
The way you formulated your request makes me think it could be homework or assignment .
Is it so?
# 5  
Old 06-05-2013
No, I wish it was a homework, that way I would still have classmates and teacher instructor to ask about that. It is actually something I am trying to do within my work... I've been working with this type of files 'by-hand' for four years, and finally decided to learn some more "advanced" unix commands and scripting that could help me be more efficient.
Thanks,
This User Gave Thanks to jaldo0805 For This Post:
# 6  
Old 06-05-2013
What works for "key" would also work for "geom.txt"...
Code:
key=345298
geo=$(cat geom.txt)
cat<<eoi>inpfile
Some standard lines of the program that is going to execute inpfile ....
$key   
$geo   # inserts contents of geom.txt here
Some other standard lines...
eoi

This User Gave Thanks to shamrock For This Post:
# 7  
Old 06-05-2013
Quote:
Originally Posted by shamrock
Code:
geo=$(cat geom.txt)

Why use cat at all? Use the shell itself geo=$(<geom.txt).
These 2 Users Gave Thanks to elixir_sinari For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Ssh cat file output into a file on local computer

Hello, I'm on a remote computer by SSH. How can I get the output of "cat file" into a file on the local computer? I cannot use scp, because it's blocked. something like: ssh root@remote_maschine "cat /file" > /locale_machine/file :rolleyes: (2 Replies)
Discussion started by: borsti007
2 Replies

2. Shell Programming and Scripting

Cat Command on File not printing "Blank" Lines?

Hello All, I have a bash script and in it at some point I call an Expect Script that does some stuff and saves its output in a ".txt" file. Example "/path/to/my/file/Expect_Output.txt" file: notice the 2nd line is empty in the file... Data for Host-1 (192.168.1.110) Checking the... (2 Replies)
Discussion started by: mrm5102
2 Replies

3. UNIX for Advanced & Expert Users

for i in `cat file` do

in bash: for i in `cat file` ; do echo $i done; how will i do this in perl ? (10 Replies)
Discussion started by: linuxgeek
10 Replies

4. Shell Programming and Scripting

Cat file

how to cat a file by ignoring first line and last line (1 Reply)
Discussion started by: thelakbe
1 Replies

5. Shell Programming and Scripting

cat in the command line doesn't match cat in the script

Hello, So I sorted my file as I was supposed to: sort -n -r -k 2 -k 1 file1 | uniq > file2 and when I wrote > cat file2 in the command line, I got what I was expecting, but in the script itself ... sort -n -r -k 2 -k 1 averages | uniq > temp cat file2 It wrote a whole... (21 Replies)
Discussion started by: shira
21 Replies

6. UNIX for Dummies Questions & Answers

Difference between cat , cat > , cat >> and touch !!!

Hi Can anybody tell the difference between Difference between cat , cat > , cat >> and touch command in UNIX? Thanks (6 Replies)
Discussion started by: skyineyes
6 Replies

7. UNIX for Dummies Questions & Answers

How to cat file

I want to cat a file with only show the line contain '/bin/bash' but don't show the line contain 'load' (don't show if the line contain 'load' and '/bin/bash' together), how to type in the command? thk a lot! (2 Replies)
Discussion started by: zp523444
2 Replies

8. UNIX for Dummies Questions & Answers

Easiest way to cat out first 100 lines of a file into a different file?

Not sure how to do this exactly.. just want to take the first 100 lines of a file and cat it out into a second file. I know I can do a more on a file and > it into a different file, but how can I make it so only the first 100 lines get moved over? (1 Reply)
Discussion started by: LordJezo
1 Replies

9. UNIX for Dummies Questions & Answers

cat and lp or pr printing of file

Can you use cat to send the first 25 lines of a file to the printer? I'm thinking I can pipe it with '|' but I'm not school to check printer output. With the 'nl' used, all lines are numbered on the print out, but how does one number only the blank lines? Thanks:) (1 Reply)
Discussion started by: bitwize
1 Replies
Login or Register to Ask a Question

Featured Tech Videos