Solved

Lunix/Unix script question on cat

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Choosing CentOS 16 108
Linux Desktop suggestion for Dell Inspiron 3043 13 55
Recover Lacie Edmini data. 11 55
LINUX Field Separators 7 38
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…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
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…
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.

828 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