Solved

Lunix/Unix script question on cat

Posted on 2015-01-28
5
184 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How do I setup Wordpress to use Master / Slave MySQL database setup? 4 133
SSL/TLS - openssl troubleshooting 3 82
RPM creation 6 49
SMTP log file for IMSVA 5 76
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 …
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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…
Suggested Courses

710 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