Solved

Lunix/Unix script question on cat

Posted on 2015-01-28
5
181 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Why VNC doesn't work in Redhat? 11 62
High Bandwidth Usage 6 58
wipe a usb using python 5 48
SUSE Linux Enterprise 11.x Ensure tftp server is not enabled 1 25
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

831 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