UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
You don't need a fax machine to get faxes. Get a fax-to-email fax number from CallWave. Try it free.
  #1  
Old July 22nd, 2004, 10:12 AM
ivalice ivalice is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 16 ivalice User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
'cat' and 'echo' advice: how to show a file in 'cat' format instead of 'echo'

Hello,

I'm writing a script that displays a current file I have in the pwd. The script line reads:

echo `cat movdb.dat`;;

(It's inside a case statement)

Anyway, echo displays the contents of the file with single spaces, between words and characters and such.

If I were to cat the file directly from the cmd line, such as :

$ cat movdb.dat

then it would have all the spacing that makes it look nice. But when I do it with echo, it does not include all the spaces and such. How can I make it so it looks like when I exe. "cat movdb.dat" from the cmd line?

Thank you.

-vi

Reply With Quote
  #2  
Old July 22nd, 2004, 10:31 AM
faulkner faulkner is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 103 faulkner User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
Instead of:
echo `cat movdb.dat`;;
use:
`cat movdb.dat` ;;

Make sure to use backticks ( ` ) and not single quotes.
Backticks should tell your shell to execute this command.
You may need to use the full path to cat. Eg: /bin/cat

Reply With Quote
  #3  
Old July 22nd, 2004, 11:41 AM
ivalice ivalice is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 16 ivalice User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
ah damn, so simple.

thanks for the revelation.

-vi

Reply With Quote
  #4  
Old July 22nd, 2004, 11:47 AM
ivalice ivalice is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 16 ivalice User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
hmm. it does not work, but i think i know why.

the particular file i am trying to cat has spaces. anyway, i changed the program to:

`cat movdb.dat`

( this is a movie database program i am trying to create, and i'm supposed to list this dat file which i created )

but when i do that, it says this:

./prog6: 0001|Lord: command not found


its trying to cat the information in that movdb.dat file, but when it hits the first "space" or "blank" ( blank space ) it gets that error.

any suggestions now ?

btw, the file is in the same directory, so i won't need the full pathname.

#####
also, the first line of the movdb.dat file is:
0001|Lord of the Rings |Bilbo Baggins |Action |12/12/52| 900000
#####


-vi

Reply With Quote
  #5  
Old July 22nd, 2004, 05:49 PM
Perderabo Perderabo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 121 Perderabo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 54 sec
Reputation Power: 5
Lose the backticks. To display a file just use:
cat movdb.dat

Add in the semicolons if you want to terminate the case selection on the same line. If you got the cat command to work on the command line, why are you screwing around with echo and backticks in the script?

Reply With Quote
  #6  
Old July 23rd, 2004, 01:45 AM
ivalice ivalice is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 16 ivalice User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by Perderabo
Lose the backticks. To display a file just use:
cat movdb.dat


Excellent. It finally displays it just the way I want it.

Quote:
Originally Posted by Perderabo
If you got the cat command to work on the command line, why are you screwing around with echo and backticks in the script?


I thought backticks where needed whenever you need something to execute on the cmd line. 'echo' was truly a intellectual blunder on my part, however, since I echo everything. Thanks for your help, in case you didn't know, i'm new to UNIX scripting .

Currently in taking an Intro to UNiX class, and its my last program for this semester.

-vi

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > 'cat' and 'echo' advice: how to show a file in 'cat' format instead of 'echo'


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway