Solved

Lunix/Unix script question on cat

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
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…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

930 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

11 Experts available now in Live!

Get 1:1 Help Now