Fomatting o/p


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Fomatting o/p
# 1  
Old 12-11-2014
Fomatting o/p

Hi Team,

I am getting newline character when I ran below script.

What I doing in the script is just formatting the input provided to that script and printing.

Code:
Output_Logging()
{
var=$1
tmp=`echo $var | cut -b 1-140`
echo "[INFO][`date +'%h %d %H:%M:%S'`]  $tmp"
var1=`echo $var | cut -b 141-|sed 's#\\\\n##g`
while true
do
if [ -z "$var1" ]
then
break
fi
x=`echo $var1 | cut -b 1-140`
echo "\t\t\t $x"
var1=`echo $var1 | cut -b 141-`
done
}
# Begin Main
if [ $# -eq 0 ]
then
   if [ -t 0 ]
   then
     echo "[INFO]   Please Input the string which you want to format"
   fi
     read input
     Output_Logging "$input"
else
   input=$@
   Output_Logging "$input"
fi

I am not getting why newline character is getting printed when I ran my script

Code:
output_log "hello"
+ [ 1 -eq 0 ]
+ input=hello
+ Output_Logging hello
[INFO][Dec 11 14:51:31]  hello
  --newline charchter here

---------- Post updated at 06:11 PM ---------- Previous update was at 05:55 PM ----------

---------- Post updated at 06:23 PM ---------- Previous update was at 06:11 PM ----------

got the error

Last edited by gvkumar25; 12-11-2014 at 07:20 PM..
# 2  
Old 12-11-2014
I suggest you change the line that reads:

Code:
var1=`echo $var | cut -b 141-|sed 's#\\\\n##g`

to read

Code:
var1=`echo $var | cut -b 141- | tr -d [\\n]`

if your only intent with that line is to remove newlines.
# 3  
Old 12-11-2014
What operating system and shell are you using?

When you run your script as follows:
Code:
output_log hello|od -c

what output do you get? When you run your script as follows:
Code:
output_log abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789 \
abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789 \
abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789|od -c

what output do you get?

If your script is invoked as shown in the above two examples, what output do you want your script to produce?
Login or Register to Ask a Question

Previous Thread | Next Thread

1 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Fomatting Solaris Hard Disk.

Hi Friends ! How long does it take to format a hard disk under Solaris ? Once the format starts, what data will be cleared or deleted first ? i.e whether the OS is cleared or all the data other than OS is cleared first ? Then, if the format starts and the power goes off, can i retrieve data?... (1 Reply)
Discussion started by: mrgubbala
1 Replies
Login or Register to Ask a Question