Trouble printing multiple lines to a new file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Trouble printing multiple lines to a new file
# 1  
Old 12-10-2011
Trouble printing multiple lines to a new file

Hi,

I'm trying to auto generate some php files with a default preamble at the top which is a block comment.

The problem is that my output has no new lines and it looks like the output from "ls" is being printed after everyline


This is my code

Code:
#!/bin/bash

read -d '' pre_amble <<"EOF"
/** 
 *
 * Default comment block at top of file
 *
 * etc etc 
 *
 * contains things like copyright info
 *
 * and author name etc
 *
 * 
 * 
 */
EOF
echo $pre_amble > 'test.php'


And this is what is in 'test.php' after the script has executed (emphasis added to make it easier to read)


Quote:
/bin /boot /cdrom /dev /etc /home /host /initrd.img /initrd.img.old /lib /lost+found /media /mnt /opt /proc /root /sbin /selinux /srv /sys /tmp /usr /var /vmlinuz /vmlinuz.old build COPYING docs extras logs README.md tests webapp build COPYING docs extras logs README.md tests webapp Default comment block at top of file build COPYING docs extras logs README.md tests webapp build COPYING docs extras logs README.md tests webapp etc etc build COPYING docs extras logs README.md tests webapp build COPYING docs extras logs README.md tests webapp contains things like copyright info build COPYING docs extras logs README.md tests webapp build COPYING docs extras logs README.md tests webapp and author name etc build COPYING docs extras logs README.md tests webapp build COPYING docs extras logs README.md tests webapp build COPYING docs extras logs README.md tests webapp build/ docs/ extras/ logs/ tests/ webapp/

Any ideas ?

Thanks
# 2  
Old 12-10-2011
Your problem is that you are reading it into a variable and the shell is doing glob expansion on the asterisks as the variable is expanded on the echo. Try this:

Code:
cat <<END >test.php
/** 
 *
 * Default comment block at top of file
 *
 * etc etc 
 *
 * contains things like copyright info
 *
 * and author name etc
 *
 * 
 * 
 */
END

Eliminates the use of the variable, and should not cause any problems with file name globbing.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Printing multiple lines on the same line between specific text

This is an extract from a large file. The lines that start with fc are ports on a fabric switch. In between each fc port there is information about the port. fc2/12 is up Port description is SEIEDISCOVER-3 Speed is 4 Gbps fc2/13 is down (Administratively down) fc2/14 is up Port... (1 Reply)
Discussion started by: kieranfoley
1 Replies

2. Shell Programming and Scripting

Removing multiple lines from input file, if multiple lines match a pattern.

GM, I have an issue at work, which requires a simple solution. But, after multiple attempts, I have not been able to hit on the code needed. I am assuming that sed, awk or even perl could do what I need. I have an application that adds extra blank page feeds, for multiple reports, when... (7 Replies)
Discussion started by: jxfish2
7 Replies

3. Shell Programming and Scripting

Printing multiple columns from a file

Hi, I need just to print the values of second and fourth column from a file # cat dispaly id Name Std Specialist 1 sss X mathematics 2 uyt IX geography 3 vcd X English i tried with some NF command.. I think am wrong.. Is there anyother way to print my requirement (3 Replies)
Discussion started by: Priya Amaresh
3 Replies

4. Shell Programming and Scripting

Printing the lines that appear in an other file, and the three lines after them

Hi ! I need some help with a script I am writing. I am trying to compare two files, the first file being in this format : Header1 Text1-1 Text1-2 Text1-3 Header2 Text2-1 etc... For each header, I want to check if it appears in the second file, and if it is the case print the header... (4 Replies)
Discussion started by: jbi
4 Replies

5. Shell Programming and Scripting

Need Help with grep printing multiple lines.

I need help in printing multiple lines using a grep command. The situation is like this. I have a file that contains large number of lines Now I need to find the the lines in the file such that if the word "AllServiceType" is found then the next line also gets printed. Does anyone... (6 Replies)
Discussion started by: m_usmanayub
6 Replies

6. Shell Programming and Scripting

printing lines to a file from a particular string

Hi, A very Good Evening to All, I am writing a script for my application. I have a file with 1000 lines. Among that 1000 lines i am searching for a particular string. And from that string i need to pull all the data in to a seperate file. For example the contents of my file is as below. ... (4 Replies)
Discussion started by: intiraju
4 Replies

7. Shell Programming and Scripting

Perl: Printing Multiple Lines after pattern match

Hello People, Need some assistance/guidance. OUTLINE: Two files (File1 and File2) File1 has some ids such as 009463_3922_1827 897654_8764_5432 File2 has things along the lines of: Query= 009463_3922_1827 length=252 (252 letters) More stufff here ... (5 Replies)
Discussion started by: Deep9000
5 Replies

8. Shell Programming and Scripting

Printing out multiple lines with a correct format

Hello, This is my first post and I've just started on UNIX in school. A file name "list" has the following content (excluding the numbers and the bottom part): 1 2 3 4 5 6 0123456789012345678901234567890123456789012345678901234567890 IT ... (1 Reply)
Discussion started by: cooolway
1 Replies

9. Shell Programming and Scripting

printing first n lines in a file without using head

i have to print first n lines of a file. how can i do that without using head command. for some reason i do not want to use Head. is there a way to get that result using awk or sed?. i an using this on korn shell for AIX Thanks.. (7 Replies)
Discussion started by: dareman123
7 Replies

10. Shell Programming and Scripting

Trouble with printing to other folders w/ awk

Again, I am in need of some advice. Earlier I was shown how to have awk create folders for me. That was so cool and helpful, but now I am exploring the posibilities of combining operations with bash scripts. Now, I am creating the directories with the bash script, and then I want awk to... (1 Reply)
Discussion started by: ccox85
1 Replies
Login or Register to Ask a Question