Echo printing a line in 2 lines; expected to print in one line
Dear All,
fileName: therm.txt
sedFile.sh
What I am trying to do is simple sed operartion to replace text "c3h6ooh1-2" with "LONG0001". Strangely it is not happening.
The sed command is attempting to substitute the string "c3h6ooh1-2" with "LONG0001 ", but it doesn't find that string, because you've put the string c3h6ooh1-2 inside quotes.
Try ---------- Post updated at 06:49 AM ---------- Previous update was at 06:38 AM ----------
Edit: Consider adding a second whitespace at the end of the replacement string LONG.., e.g.
so a 10 character string gets replaced by a 10 character string, otherwise the indentation will change.
This User Gave Thanks to junior-helper For This Post:
What junior-helper suggested should make your sed command work. But, this thread is titled: "Echo printing a line in 2 lines; ecpected to print in one line". I don't see any echo commands and I don't see any indication that extraneous <newline>s are being added by anything you've shown us.
Is there something else we're missing here?
This User Gave Thanks to Don Cragun For This Post:
now I am able to sed, Thanks a lot.
I have another issue.
content of my file:
similar to previous sed commands I wanted to sed "al" and " al2h6" with some other word like LONG0003 say ...
but problem is sed will replace all "al"s
How can I get-ride of this situation?
I assume you used something like sed 's/al/LONGsomething/g' file
The "problem" is /g means global replacement, thus sed will attempt to replace all occurences of the al string, no matter where in the line.
Quote:
> How can I get-ride of this situation?
If you remove g from the sed command like this sed 's/al/LONG/' file sed will only replace the first occurence of al.
By using a caret ^, you explicitely tell sed to match al at the beginning of the line:
The above would *almost* do what you want... Why almost? It will replace all al's which are at the beginning of the line, so al gets LONG, and al2h6 gets LONG2h6 You get the idea.
THIS is what you want for al (it acts like replace al only found as single string, not as part of some other string too)
and this for al2h6
This User Gave Thanks to junior-helper For This Post:
... ... ...
similar to previous sed commands I wanted to sed "al" and " al2h6" with some other word like LONG0003 say ...
but problem is sed will replace all "al"s
How can I get-ride of this situation?
Thanks & Regards,
linuxUser_
ljunior-helper has already pointed out some of the issues with your last post. Let me expand on that a little bit.
No. A sed substitute command will replace the text you tell it to match with the text you tell it to substitute. It will only replace all instances of al if you tell it to replace all instances of al.
If you don't want it to replace all instances of al, describe more precisely what you want to match and what text you want to use to replace the matched text.
Your latest sample input file contains four instances of al and one instance of al2h6. One of those instances of al is at the start of a line and is followed by six spaces. One instance of al2h6 is at the start of a line and is followed by 3 spaces.
Can you precisely define what you want to match and what text you want to replace the text you match?
From your last request, I would guess that you don't want to replace al or al2h6, but instead want to replace eight characters at the start of a line starting with al with the eight replacement characters LONG0003. If that is what you want, that would be something more like:
Please stop making us guess at what you want and give precise details about what you are trying to do.
This User Gave Thanks to Don Cragun For This Post:
Currently using below script but echo it print the output in two line.
Input file all-vm-final-2.txt
CEALA08893 SDDC_SCUN DS_SIO_Workload_SAPUI_UAT_01 4
CEALA09546 SDDC_SCUN DS-SIO-PD5_Workload_UAT_SP1_Flash_07 4
CEALA09702 SDDC_SCUN DS-VSAN-RMP-WORKLOAD01 4
DEALA08762 SDDC_LDC... (3 Replies)
Hi All,
i want to write a shell script read below file line by line and want to exclude the lines which contains empty value for MOUNTPOINT field.
i am using centos 7 Operating system.
want to read below file.
# cat /tmp/d5
NAME="/dev/sda" TYPE="disk" SIZE="60G" OWNER="root"... (4 Replies)
Hello,
I've been trying to find the answer to this with Google and trying to browse the forums, but I haven't been able to come up with anything. If this has already been answered, please link me to the thread as I can't find it.
I've been asked to write a script that pulls a list of our CPE... (51 Replies)
This is an extract from a large file. The lines that start with fc are ports on a fabric switch. In between each fc port there is information about the port.
fc2/12 is up
Port description is SEIEDISCOVER-3
Speed is 4 Gbps
fc2/13 is down (Administratively down)
fc2/14 is up
Port... (1 Reply)
Hello,
I need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line... An example of entries in the file would be:
SRVXPAPI001 ERRO JUN24 07:28:34 1775
REASON= 0000, PROCID= #E506 #1065: TPCIPPR, INDEX= 003F
... (8 Replies)
Dear all
I want to search special string in file and then print next all line in one line until blank lines come. Help me plz for same. My input file and desire op file is as under.
i/p file:
A1/EXT "BSCABD1_21233G1" 757 130823 1157
RADIO X-CEIVER ADMINISTRATION
BTS EXTERNAL FAULT
... (7 Replies)
Hi consider the source file
R|field1|field2
using the print statement in awk prints it as
R field1 field2
Is there an easier way to print the whole line in its original format (i.e. with | delimiters) than doing print $1"|"$2"|"$3 ??
Thanks
Storms (1 Reply)
Hi,
I have written this code
------------------------------------------------
# !/bin/ksh
i=0
while
do
j=$i
while
do
echo -e $j
#printf "%d",$j
j=`expr $j - 1`
done
echo
i=`expr $i + 1`
done
----------------------------------------------------
The ouput which... (2 Replies)
Hi all,
This should be very easy but I can't figure it out...
I have a file that looks like this:
@SRR057408.1 FW8Y5CK02R652T length=34
AGCAGTGGTATCAACGCAGAGTAAGCAGTGGTAT
+SRR057408.1 FW8Y5CK02R652T length=34
FIIHFF6666?=:88@@@BBD:::?@ABBAAA>8
@SRR057408.2 FW8Y5CK02TBMHV length=52... (1 Reply)