Sponsored Content
Full Discussion: Perl command modification
Top Forums Shell Programming and Scripting Perl command modification Post 302922490 by Akshay Hegde on Saturday 25th of October 2014 01:09:11 PM
Old 10-25-2014
Try like this

Code:
akshay@nio:/tmp$ cat p.pl
#!/usr/bin/perl

use warnings;
use strict;

foreach my $cmd (('/bin/uname -a','ls -ltr','pwd')){

open CMD,'-|',"$cmd" or die $@;
my $line;
print "\nCommand : $cmd \n";
while (defined($line=<CMD>)) {
    print $line; 
}
close CMD;

}

Code:
akshay@nio:/tmp$ perl p.pl

Command : /bin/uname -a 
Linux Aix 3.8.0-29-generic #42~precise1-Ubuntu SMP Wed Aug 14 15:31:16 UTC 2013 i686 i686 i386 GNU/Linux

Command : ls -ltr 
total 72
drwx------ 2 akshay akshay 4096 Jan  1  1970 orbit-akshay
drwx------ 2 root   root   4096 Oct 25 20:38 pulse-PKdhtXMmr18n
drwx------ 2 root   root   4096 Oct 25 20:38 pulse-2L9K88eMlGn7
-rw-rw-r-- 1 akshay akshay    0 Oct 25 20:39 unity_support_test.0
drwx------ 2 akshay akshay 4096 Oct 25 20:39 ssh-SRRdshaL1886
drwx------ 2 akshay akshay 4096 Oct 25 20:39 keyring-cfR6TC
drwx------ 2 akshay akshay 4096 Oct 25 20:39 pulse-ZUhHRVImGZzf
-rw------- 1 akshay akshay    0 Oct 25 20:40 tmpx9PyKR
-rw-r----- 1 akshay akshay   32 Oct 25 20:51 adb.log
drwxr--r-- 2 akshay akshay 4096 Oct 25 20:51 android-akshay
-rw-rw-r-- 1 akshay akshay 1838 Oct 25 20:51 filef8zK8X
drwxrwxrwx 2 akshay akshay 4096 Oct 25 20:52 swtlib-32
drwxr-xr-x 2 akshay akshay 4096 Oct 25 20:52 hsperfdata_akshay
-rw-rw-r-- 1 akshay akshay  314 Oct 25 21:16 cmp.awk~
-rw-rw-r-- 1 akshay akshay  314 Oct 25 21:16 cmp.awk
-rw-rw-r-- 1 akshay akshay 1125 Oct 25 21:16 p~
-rw-rw-r-- 1 akshay akshay 1156 Oct 25 21:16 p
-rw-rw-r-- 1 akshay akshay  127 Oct 25 21:28 f
-rw-rw-r-- 1 akshay akshay  232 Oct 25 22:21 p.pl~
-rw-rw-r-- 1 akshay akshay  234 Oct 25 22:21 p.pl

Command : pwd 
/tmp

---------- Post updated at 11:39 PM ---------- Previous update was at 11:24 PM ----------

OR you can create small subroutine like this

Code:
#!/usr/bin/perl

use warnings;
use strict;


sub system_cmd{
	my @return;
	open CMD,'-|',"@_" or die $@;
	my $line;
	while (defined($line=<CMD>))
	{
	    	push(@return, $line); 
	}
	close CMD;
	return @return;
}


foreach my $cmd (('/bin/uname -a','ls -ltr','pwd'))
{
	my @output =system_cmd($cmd);
	
	print "\nCommand : $cmd \n";
	print "@output";
}

This User Gave Thanks to Akshay Hegde For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

command for modification date of a file

Good morning, I would like to find all files of a certain type and display their name as well as their modification date. In order to do this, I would do the following: find ./ -name *.csv | ???????? My question: what to put after the pipe instead of the question marks? Is there a basic... (5 Replies)
Discussion started by: scampsd
5 Replies

2. Shell Programming and Scripting

Need help with a slight modification to my PERL script

Hi all, So I have a script that reads a file called FILEA.txt and in that file there are several columns. The ones that are most important are the $name $start and $stop. So currently the script takes values between the start and stop (inside) by using a program called fastamd. But what I... (4 Replies)
Discussion started by: phil_heath
4 Replies

3. Solaris

Command for checking modification history on file

What is the command for checking modification history on file? ---------- Post updated at 01:20 PM ---------- Previous update was at 12:35 PM ---------- Let me rephrase this. On a regular Unix file can I at least check to see the time and date history modification of the file? (6 Replies)
Discussion started by: jastanle84
6 Replies

4. Shell Programming and Scripting

Excel sheet modification using perl module

Is there any possibility to move the content from one cell to another cell (Excel sheet) using perl module? (3 Replies)
Discussion started by: kavi.mogu
3 Replies

5. Shell Programming and Scripting

Excel sheet modification using perl module

I need to insert new column to already existing file ..can any one help me..?? (6 Replies)
Discussion started by: kavi.mogu
6 Replies

6. Shell Programming and Scripting

Excel sheet modification using perl module

Hi , Is there any possibility to read excel sheet in column by column order ?...Thanks in advance,........ :confused: (1 Reply)
Discussion started by: kavi.mogu
1 Replies

7. Programming

Excel sheet modification using perl module

Hi , can any one tell me,"How to extract the same format from existing excel file to new excel file " using Spreadsheet::WriteExcel or Spreadsheet::ParseExcel module ??? Example_pgm: Below program is used to read existing excel file..In this program "my $cell = $_;" line is used to... (0 Replies)
Discussion started by: kavi.mogu
0 Replies

8. Shell Programming and Scripting

Modification to awk command

i have a php file that has this: php.code #!/usr/bin/php <?php phpinfo(); hlight_file(__FILE__); ?> I want my awk code grab whatever is inbetween and including the "<?php" and "?>". Then, it should scan all the entries between these two points. And if the entries between these... (10 Replies)
Discussion started by: SkySmart
10 Replies

9. Shell Programming and Scripting

Help with command modification

Hello folks; I'm using the following command to get the highest number of requests per second in a log file and it works well. grep "2017-02-22" "LogFile.log" | cut -c1-20 | uniq -c | sort -n | tail -n1 Now i would like to also get the smallest requests per second and the amount of time... (5 Replies)
Discussion started by: Katkota
5 Replies

10. Shell Programming and Scripting

Modification of perl script to split a large file into chunks of 5000 chracters

I have a perl script which splits a large file into chunks.The script is given below use strict; use warnings; open (FH, "<monolingual.txt") or die "Could not open source file. $!"; my $i = 0; while (1) { my $chunk; print "process part $i\n"; open(OUT, ">part$i.log") or die "Could... (4 Replies)
Discussion started by: gimley
4 Replies
LSMBOXRC(5)							File Formats Manual						       LSMBOXRC(5)

NAME
lsmboxrc - configuration file for lsmbox DESCRIPTION
A lsmbox configuration file consists of a list of configuration options and their setting. The hash mark ("#") is used as a "comment" character. Every line beginning with a comment character is ignored. Whitespace is also ignored. COMMANDS
set variable=value Set a configuration variable to the specified value. unset variable Unset a configuration variable. This implies that the built-in default will be used instead. mailboxes filename... Specifies what mailboxes to check. You can have one or several of these lines. Each line can contain the name of one or more mail- boxes, each separated by a space. A filename of ! denotes your inbox. A leading ("=") or ("+") in a filename will be expanded into the path to your mail-directory. CONFIGURATION VARIABLES
folder The path to your mail-directory; this is usually $HOME/Mail/. lsmbox_mail_command Specifies what command to execute when the user selects a mailbox in continuous mode. mark_old Specifies whether or not old unread messages and new messages should be accounted separately. If you explicitly unset this variable using the unset command, the number of new and old messages will be added together as unread messages, otherwise they will be accounted as new and old respectively. mh_seq_unseen Specifies the string used in the .mh_sequences file to list new/old unread messages. If this variable is not set, or explicitly unset, "unseen" will be used. spoolfile The path to where the system keeps your inbox; usually /var/mail/USERNAME or /var/spool/mail/USERNAME. lsmbox_padding The width of the mailbox column. To never add additional padding beyond what's needed to align all values, specify '0' here. COMMENTS
You cannot specify a path or mailbox that contains whitespace characters (space, newline, etc.) Do not bug me about this. Having such filenames/pathnames is stupid anyway. I've deliberately tried to use the same syntax as mutt uses for its configuration-file muttrc whenever possible, to facilitate sourcing of $HOME/.lsmboxrc from your $HOME/.muttrc. lsmbox_mail_command will, however, cause mutt to emit an error. SEE ALSO
lsmbox(1), muttrc(5) HISTORY
Apr 16 2006: Updated for v2.1.0 of lsmbox. Apr 16 2004: Updated for v2.0.0 of lsmbox. Mar 13 2004: Updated for v1.9.0 of lsmbox. Jan 16 2003: Minor fixes. Jan 06 2003: Minor fixes. Dec 09 2002: Minor fixes. Nov 15 2002: Updated for v1.6.0 of lsmbox. Nov 13 2002: Add note about '+' and '='. Nov 06 2002: Minor changes. Nov 04 2002: Minor change. Oct 29 2002: Fixed a typo. Oct 28 2002: Fixed a typo. Oct 26 2002: Updated for v1.1.0 of lsmbox. Oct 26 2002: Updated for v1.0.1 of lsmbox. Oct 21 2002: Initial release. AUTHOR
lsmbox and its manual-pages are written by David Weinehall <tao@acc.umu.se> REPORTING BUGS
Report bugs to <tao@acc.umu.se>. COPYRIGHT
Copyright (C) 2002-2006 David Weinehall This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICU- LAR PURPOSE. David Weinehall Apr 16, 2006 LSMBOXRC(5)
All times are GMT -4. The time now is 04:25 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy