Solved

Lunix/Unix script question on cat

Posted on 2015-01-28
5
179 Views
Last Modified: 2015-01-28
I 'm wating a script and  just catting the file put into the log file, there 6 lines on the file, but when it put into the log file it is puttig in single line.

#!/bin/bash -x

PWD=`pwd`
HOST=aixhost1
LOG=$HOST
echo $LOG
touch $LOG
echo `cat $PWD/testing` >> $LOG

I have file
0
Comment
Question by:mokkan
  • 2
  • 2
5 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 40575505
Why should you want to use "echo" with "cat"?

This is sufficient:

cat $PWD/testing >> $LOG

The cause of your issue is that "echo" strips linefeeds (and adds one at the end only).
To avoid this you could do:

echo "`cat $PWD/testing`" >> $LOG
or (better readable):
echo "$(cat $PWD/testing)" >> $LOG

Please note the quotation marks!

But as I said, "echo" is unnecessary.
0
 

Author Comment

by:mokkan
ID: 40575532
Hey, that helpedddddddddd . Thank you very much
0
 

Author Comment

by:mokkan
ID: 40575572
How about if I want to run a commnad get the output line by line.

 I am trying a command , and it has 5 lines, but I can only use echo command

echo `/sbin/lltstat -nvv active` >> $LOG
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 40575607
Well, I'm not familiar with lltstat. Seems it's used to report LLT statistics, right?

Anyway, what do you mean with "line by line", and why in the world "echo"?

I'm rather sure that this is not what you want:

for line in $(/sbin/lltstat -nvv active)
   do
      echo "This is a line:" $line
      echo "Hit <Enter> for next line"
       read IN
   done

But what else?
0
 
LVL 84

Expert Comment

by:ozo
ID: 40575609
/sbin/lltstat -nvv active >> $LOG
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now