why does cat come back with separate lines in shell script?

why does cat come back with separate lines in shell script?

Post by Gonzale » Sun, 25 Mar 2001 00:28:38



When I cat a file on the command line each field (3 fields) are on the same
line,
but when I try to use `cat $file` in a script, each of the 3 fields are all
on separate
lines and it's screwing up my program.
 
 
 

why does cat come back with separate lines in shell script?

Post by car.. » Sun, 25 Mar 2001 03:19:19


 >When I cat a file on the command line each field (3 fields) are on the same
 >line,
 >but when I try to use `cat $file` in a script, each of the 3 fields are all
 >on separate
 >lines and it's screwing up my program.

Try with double-quotes, i.e. "`cat $file`"

cheers
--
Contro i brevetti software - Against software patents
http://petition.eurolinux.org - http://no-patents.prosa.it

 
 
 

why does cat come back with separate lines in shell script?

Post by Michael Velte » Sun, 25 Mar 2001 02:58:30



Quote:> When I cat a file on the command line each field (3 fields) are on the
> same line, but when I try to use `cat $file` in a script, each of the
> 3 fields are all on separate lines and it's screwing up my program.

Which shell are you using? Here (bash) I can't reproduce this
behaviour. I'd propose that you post the relevant part of your script.

Michael

 
 
 

why does cat come back with separate lines in shell script?

Post by Gonzale » Sun, 25 Mar 2001 06:57:46




>  >When I cat a file on the command line each field (3 fields) are on the
same
>  >line,
>  >but when I try to use `cat $file` in a script, each of the 3 fields are
all
>  >on separate
>  >lines and it's screwing up my program.

> Try with double-quotes, i.e. "`cat $file`"

> cheers
> --
> Contro i brevetti software - Against software patents
> http://petition.eurolinux.org - http://no-patents.prosa.it

 Carlos,

That worked!  Thanks so much!

 
 
 

1. Why can't I field-separate this line?

I have a line like this by doing 'tail -1 somefile':

/dev/hda3     28851852   5759880   23091972   20%  /

What I want to do is first print only the first column (/dev/hda3) and
eventually extract the hda3 out of it.  But, tail -1 somefile | gawk
-F=" " '{print $1}' only gives me the entire line.  I am suspecting
it's because of the /s in the line.  How would I get around this?
Thanks,
-j

2. cvs server: cannot open /root/.cvsignore: Permission denied

3. Why is `cat` parsing lines?

4. Modem Speaker ON/OFF?

5. script to separate characters of a line in a file

6. Help with Possible system hack !!! how to find more info ?

7. How to do 'for line in `cat file`; do' in bourne shell?

8. terminal trouble with xdm

9. # How to read a textfile line by line using csh shell script ?

10. unix shell script to access a file line by line

11. How to read text line-by-line in shell script?

12. Accessing a shell script w/o doing . /script

13. Question about shell script, can you enter a script at a specific line?