Removing "^M" from the end of a String (i.e. "Ctrl+M")?
Hello All,
I have an Expect script that ssh's to a remote server and runs some commands before exiting.
One of the commands I run is the "hostname" Command. After I run this command I save the output
using this line in the code below...
Basically it executes the hostname command, then I loop through the "$expect_out(buffer)" variable
line by line. The "$expect_out(buffer)" variable holds the output of the last "send" command, up to
the next "expected" ouput.
The reason I know that it's showing a "^M" at the end of that variable, is because I redirected the output
to a file on one of my tries, and while viewing the output in vi I was able to see the special characters.
And this is the output from the "puts" command. It shows like this below (notice the quotation mark is begin
moved to the start of that line.)...
As you can see the last quotation mark is replacing the first character on the same line...
Any thoughts how I could get rid of this "^M" from my variable..? It would be VERY much appreciated!
I gave that a shot and I still am getting the same result...
I also switched out your "pattern" with "\^M" and "\\^M" and still no luck.
I ran my Expect Script with the tee command to check out the real output. And if I open the file created from the tee command
I can see this line for the output for the Hostname.
Now if you view the output in STDOUT it looks like this (F.Y.I. I printed it with escaped parentheses to view the start/ending points of the variable)...
But anyway, thanks for the "regsub" command though. I've been looking for a command like that.
Thanks Again,
Matt
---------- Post updated at 09:58 AM ---------- Previous update was at 09:53 AM ----------
UPDATE:
Humm... Looks like the "^M" is actually the same thing as a carriage return --> "\r"...
So I switched out the pattern to match with the "\r" and it seems to be working..!!!
And the output looks good, both in STDOUT and in the file fro the tee command.
Thanks for the regsub command, exactly what I needed! I appreciate your reply.
Hi 2 all,
i have had AIX 7.2
:/# /usr/IBMAHS/bin/apachectl -v
Server version: Apache/2.4.12 (Unix)
Server built: May 25 2015 04:58:27
:/#:/# /usr/IBMAHS/bin/apachectl -M
Loaded Modules:
core_module (static)
so_module (static)
http_module (static)
mpm_worker_module (static)
... (3 Replies)
Hello.
System : opensuse leap 42.3
I have a bash script that build a text file.
I would like the last command doing :
print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt
where :
print_cmd ::= some printing... (1 Reply)
Dear Ladies & Gents,
I have a requirement to delete all the log files in /var/log/test directory that are older than 10 days and their first line begin with "MSH" or "<?xml" or "FHS". I've put together the following BASH script, but it's erroring out:
for filename in $(find /var/log/test... (2 Replies)
How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address
and column 3 contains “cc” e-mail address to include with same email.
Sample input file, email.txt
Below is an sample code where... (2 Replies)
Hello.
Following recommendations for one of my threads, this is working perfectly :
#!/bin/bash
CNT=$( grep -c -e "some text 1" -e "some text 2" -e "some text 3" "/tmp/log_file.txt" )
Now I need a grep success for some thing like :
#!/bin/bash
CNT=$( grep -c -e "some text_1... (4 Replies)
logs:
"/home/abc/public_html/index.php"
"/home/abc/public_html/index.php"
"/home/xyz/public_html/index.php"
"/home/xyz/public_html/index.php"
"/home/xyz/public_html/index.php"
how to use "cut" or "awk" or "sed" to get the following result:
abc
abc
xyz
xyz
xyz (8 Replies)
Hi,
Could anyone please shed some light on the following script lines and what is it doing as it was written by an ex-administrator?
cat $AMS/version|read a b verno d
DBVer=$(/usr/bin/printf "%7s" $verno)
I checked that the cat $AMS/version command returns following output:
... (10 Replies)
Hi,
I have line in input file as below:
3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL
My expected output for line in the file must be :
"1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL"
Can someone... (7 Replies)
Hi Friends,
Can any of you explain me about the below line of code?
mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`
Im not able to understand, what exactly it is doing :confused:
Any help would be useful for me.
Lokesha (4 Replies)