473,467 Members | 1,919 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

To remove trailing prompt from the output

8 New Member
Iam trying to connect to the remote Linux machine from the Windows box using the Perl module use Net::Telnet.The following is the code,

Expand|Select|Wrap|Line Numbers
  1. use Net::Telnet;
  2. $telnet = new Net::Telnet (Timeout=>10,Errmode=>'die');
  3. $telnet->open('hostname');
  4. $telnet->waitfor('/login: $/i');
  5. $telnet->print('username');
  6. $telnet->waitfor('/password for tsom31: $/i');
  7. $telnet->print('password');
  8.  
  9. @r=$telnet->cmd('who');
  10. print @r;
It gives the output as shown below,

Expand|Select|Wrap|Line Numbers
  1. who
  2. login: Resource temporarily unavailable while getting initial credentials
  3. Last login: Thu Mar  6 10:20:30 from 192.168.*.*
  4. [tsom31@tsom31 ~]$ who
  5. root     :0           Mar  4 07:35
  6. root     pts/3        Mar  6 07:46 (192.168.*.*)
  7. tsom31   pts/4        Mar  6 10:21 (192.168.*.*)
  8. root     pts/2        Mar  6 07:29 (:0.0)
  9. [tsom31@tsom31 ~]
From the output i should remove the Last Prompt
for ex:[tsom31@tsom31 ~]

please some one help me in this

Thanks in advance..........

Regard's
Thamayanthi
Mar 6 '08 #1
5 2080
nithinpes
410 Recognized Expert Contributor
If you want to remove the last line in the output unconditionally, remove the last element of the array before printing it.
Expand|Select|Wrap|Line Numbers
  1. pop @r;
  2. print @r;
  3.  
If you want to remove last line only if it is a prompt,use:
Expand|Select|Wrap|Line Numbers
  1. pop @r if($r[$#r]=~/^\[.*\]$/);
  2. print @r;
  3.  
Mar 6 '08 #2
thamayanthi
8 New Member
Thank for your reply........

It's a wonderful solution!!!!

I have tried that command and it is working fine.

one more doubt i have is how to remove the first few lines of the same output
for ex:
who
login: Resource temporarily unavailable while getting initial credentials
Last login: Thu Mar 6 12:09:51 from 192.168.70.71
[tsom31@tsom31 ~]$ who

this need to be removed while printing.

please suggest me if you have any idea about this..............

Regard's,
Thamayanthi
Mar 6 '08 #3
nithinpes
410 Recognized Expert Contributor
Use shift to remove elements from begining of array. I am again assuming you want to remove lines from begining upto a line where you reach a prompt.
Expand|Select|Wrap|Line Numbers
  1. my $i=0;
  2. shift @r until($r[$i++]=~/^\[/); ## delete lines upto prompt
  3. shift @r; # delete line with prompt
  4. pop @r if($r[$#r]=~/^\[.*\]$/);
  5. print @r;
  6.  
Mar 6 '08 #4
thamayanthi
8 New Member
Hi,

If i add the above code in the program it is taking long time to execute..I didn't get any output.

please help me in this.........



Regard's
Thamayanthi.
Mar 7 '08 #5
nithinpes
410 Recognized Expert Contributor
Hi,

If i add the above code in the program it is taking long time to execute..I didn't get any output.

please help me in this.........



Regard's
Thamayanthi.
How many lines does your output contain approximately? The code worked for me. If this doesn't work, post your most recent code(whole script).

Expand|Select|Wrap|Line Numbers
  1. @r=$telnet->cmd('who');
  2. my $i=0;
  3. shift @r until($r[$i++]=~/^\[/); ## delete lines upto prompt
  4.  
  5. pop @r if($r[$#r]=~/^\[.*\]$/);
  6. print @r;
  7.  
Regards,
Nithin
Mar 7 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: McKirahan | last post by:
How would I use a regular expression to remove all trailing Carriage Returns and Line Feeds (%0D%0A) from a textarea's value? Thanks in advance. Also, are they any great references for learning...
5
by: Donald Canton | last post by:
What's the best way to remove trailing whitespace from a string? For example: "John C. Doe \t" would become "John C. Doe". Thanks.
4
by: ucfcpegirl06 | last post by:
Hi, I need help getting rid of trailing white spaces. I am searching a file for various data (not important) and retrieving it. I output the data if found to a file. An example would be:...
0
by: Seth | last post by:
First off, my apologies if this is in the wrong newsgroup, but I hope I'm close enough. I'm trying to do some parsing of a CSV file using OleDbConnection, but for some reason, when I populate my...
10
by: Brian Gruber | last post by:
Hi, I'm looking for a way to rename a whole directory of files in short order. The files in the directory have different lengths, however all of them end with _xxxx the x's represent a randomly...
22
by: fynali | last post by:
Hi all, I have two files: - PSP0000320.dat (quite a large list of mobile numbers), - CBR0000319.dat (a subset of the above, a list of barred bumbers) # head PSP0000320.dat CBR0000319.dat...
17
by: tommy | last post by:
Hi all, I' m adding strings to some fields in my table via Access. The strings sometimes have trailing spaces and I really need to have it that way, but Access truncates trailing spaces. How can...
3
by: Paul | last post by:
Hi, My RichTextBox has multiple lines of text. Most of the lines unfortunately end with a space. Is it possible to replace the space and NewLine/Line Feed with just the NewLine/LineFeed? So...
4
by: lihao0129 | last post by:
Hi, folks: I recently went through a strange problem with my Javascript code, say: I have a string variable which are from a 'textarea' element and I want to remove the trailing newlines inside...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.