I've visited this forums for a long time and normally got an right answer but this time my problem doesn't seem to go away. What I'm trying to do is the following:
(The count of newlines is varying!)
If I echo this i get:
Now I want to Remove empty lines. Remember that the count of newlines is varying. I'm using the following sed command:
When I echo this I get:
However if I want to save it to $VAR something strange happens:
I use:
But as I'm cutting $VAR in a while loop
it doesn't seem to work. It doesn't recognize the newlines anymore and cuts away nothing. However, it cuts off in the right manner when I don't execute the sed-command, but I need to get rid of the empty newlines. I also tried changing the command to:
etc.
and many other versions but I can't seem to find the right answer.
Use CODE-tags when displaying code, data or logs to enhance readability, ty.
Hm I don't really see a curiousity - maybe I missed it or did not get what you want. Here is what I did, smiliar to yours:
I don't understand what your goal is. If the desired output is echoing the variable with double quotes around it, that's just it?!
Use CODE-tags when displaying code, data or logs to enhance readability, ty.
Hm I don't really see a curiousity - maybe I missed it or did not get what you want. Here is what I did, smiliar to yours:
...
I don't understand what your goal is. If the desired output is echoing the variable with double quotes around it, that's just it?!
Hi zaxxon,
Thanks for trying to help me
In my script these line1,...,line7,... are the columns of different database tables, i just tried to make it simple
The problem is that I'm cutting away the different parts in a loop to get access to the single statements between the \n, e.g. i'm cutting away the back and as a result i get "line1" in the first iteration of the while loop and i cut the part out which i just selected (i cut out "line1\n" in the first iteration). I use these commands:
but it doesn't seem to work with the sed-edited version. It doesn't recognize the newlines anymore and cuts away nothing. However, it cuts off in the right manner when I don't execute the sed-command and just execute the loop on the original $VAR, but I get all the empty lines of the variable and i really need to get rid of the empty newlines.
I guess I am still not getting it - let's try to make it very simple. Just post an example input and an example of the desired output. I don't understand why you want to cut out newlines that are not there. That's where I am stuck. Also is it important you save all those strings to 1 variable and then work it again with a while loop? Maybe there is a simpler more clear way if you post the requested examples Let's give it a try.
I'm writing a shell script in AIX and using ksh.
I have a scenario where I have a variable A which stores $B.
so when i echo "$A" it prints $B
But I wish to print value stored in var b ie. \a\dir\res\
I wish to store \a\dir\res\ in a third variable C.
later I want to cd into that path :... (1 Reply)
Hi,
I'm new here so I want to say hello to everyone first!
I searched google and this forum for a similar problem, but wasn't successful
#! /bin/bash
I'm trying to output (echo) n lines of a text file to the screen (later into another file).
But I have problem with the sed command, it won't... (1 Reply)
I encountered a problem on one of our database servers.
OS: CentOS 5.5 final
Kernel: 2.6.18-238.5.1.el5.028stab085.2 (OpenVZ kernel)
We wrote some DB-Start/Stop-scripts ("/db2/admin/scripts_dba/start_services.ksh" and ".../stop_services.ksh") to start the database instances. (Database... (1 Reply)
Hi Guys!
I am facing Problem with SVM I mention the problem below:
I have Sunfire V210 machine and the partitions are as follows:
Part Tag Flag Cylinders Size Blocks
0 root wm 0 - 6134 29.77GB (6135/0/0) 62429760
1 swap wu ... (1 Reply)
Hi,
I am experiencing a weird thing on my SUNFIRE machine with Solaris 9 OS.
When I do init 0 to shutdown the machine to go to ok prompt, what it did was shutdown and reboot like an init 6 command do. I did check the corresponding rc scripts that were involved with init 0 and compared with rc... (2 Replies)
Dear all,
I typed in init 1 on my redhat box as root and according to wikipedia (http://en.wikipedia.org/wiki/Runlevel):
1 Single-User Mode Does not configure network interfaces, start daemons, or allow non-root logins
So now I can't connect back to it. How do I change the init back to 3?... (8 Replies)
I am using GNU sed but this does not output "what". Why?
HEY=$(echo "hey 70.70.70.70:21 what: " | sed -nr 's/.*(70.70.70.70\|71.71.71.71):(21\|22\|115\|443\|989\|990) (.*):.*/\3/p')
echo $HEY (2 Replies)
Hi,
I am using RHEL4 and I am not booting my computer into graphics mode
i.e. It gets hangs after the step of Enabling swap space...
I.e system is not able to enter into runlevel 5.
However, when I boot it into 'runlevel3' and then I do "#startx",
It enetrs... (1 Reply)
Hi Expert,
I have encountered some problem with my SUN system. Everytime when i issue command #init 6 OR #init 0 it just logout and prompt for login again instead of rebooting the server when run init 6 and system shutdown when run init 0..
I can only reboot the system using reboot ... Was... (6 Replies)
While concatenating 2 values, one which expanded to fixed width & other not, I am not getting value expanded as fixed width.
Following is script for the same :
#!/bin/sh
var1="abc"
var2="def"
var1Fxd=`echo $var1 | awk '{printf("%-6s",$0)}'`
echo $var1Fxd""$var2
But, if I try -
echo... (2 Replies)