Perl is a high-level, general-purpose, interpreted, dynamic programming language. It was originally developed by Larry Wall as a general-purpose Unix scripting language to make report processing easier, over a period with support from open source community, it has evolved and matured to be used for ...
1
vote
3answers
52 views
How to convert from one date format to other format?
I have one problem with my date format. I want to change from one format to the other and vice versa. My date formats are
Format 1
YYYY-MM-DD
Format 2
MM/DD/YYYY
I want to change format 1 to ...
3
votes
6answers
66 views
Only show the lines that are in all textfiles at least once
a.txt
cat a.txt
a
b
x
c
b.txt
cat b.txt
d
e
a
f
the q:
SOMEMAGICK *.txt
a
Q: how can I show only the lines that are in all *.txt files?
1
vote
1answer
26 views
how to clean free row/column spaces after the row of your data
I have a problem in cleaning my file where there are unnecessary free spaces below my last data row. This is created when I am copying and pasting my data from excel to text. I want my text file to ...
1
vote
1answer
32 views
How do I modify this Perl solution so that it will substitute embedded double quotes with single quotes?
Previously in this question: "string having doublequotes in between apart from the enclosing quotes" @BernieReiter asked a follow-up question where he wanted to take CSV entries such as the following:
...
-3
votes
0answers
45 views
How to split files using Perl? [migrated]
Each div should be separated as individual files.
Input.txt
[[div]]
line 1
line 2
...
[[/div]]
[[div]]
line 3
line 4
line 5
...
[[/div]]
[[div]]
line 6
line 7
...
[[/div]]
filename.txt
fm.html
...
0
votes
1answer
34 views
How to split files?
Input.txt
line.....1
line.....2
line.....3
.....
line.....3
line.....4
line.....5
.....
line.....4
line.....5
line.....6
.....
line.....5
line.....6
line.....7
.....
Condition for output file ...
3
votes
3answers
115 views
importing data from a text file to a bash script
I need to import a text file like this below:
AMBI
CBNK
CCXI
CERE
CLACW
CNYD
DAEG
DLIA
DLLR
DNDN
DSGX
HAST
HIBB,
HPOL
IRDMZ
MARK
NEPT
NFEC
NINE
NRCIB
OMER
PLCC
PLPM
PSUN
UNTK
There are 25 entries, ...
-1
votes
1answer
45 views
How can I split a file into multiple files based on pattern using perl? [closed]
How can I split a file into multiple files based on pattern using perl?
Ex: input to be a .txt file, name of the output file stored in another .txt file
0
votes
1answer
70 views
Automation tasks for system administrators [closed]
If I am a junior UNIX/Linux system administrator, and I want to make automation tasks for the server.
I know Shell script, Perl, and Python. All of these are used to make automation tasks.
Which one ...
1
vote
3answers
35 views
How to limit MAX an MIN length of a string?
"nothing" means no OUTPUT.
Q: how can I limit the MIN and MAX length of a piped STRING? (MIN: x>=3 chars, MAX: x<=32 chars)
INPUT:
echo 12 | MAGIC
OUTPUT:
nothing
INPUT:
echo 123 | ...
1
vote
1answer
23 views
How to make URL's out of this text with least resources?
INPUT:
nyeeeeeeeeeeeeeee.txt:sadfsadf
sadjflsajfd:jasdlfjalsfd
foo/asdfsafd.txt:laksjdlfajsfd
OUTPUT:
<a href="nyeeeeeeeeeeeeeee.txt">nyeeeeeeeeeeeeeee.txt</a>:sadfsadf
<a ...
1
vote
0answers
37 views
Why wouldn't Perl CGI script run
I'm using Apache on CentOS and am trying to run a Perl CGI script as directory index so it will run automatically as a subdomain. I added DirectoryIndex script.cgi and added a Directory stanza noting ...
0
votes
2answers
57 views
Programmatically get folders last edit time
How can I programmatically get a folders latest edit?
I have already written the following script:
#!/usr/bin/perl
my @ls_command_result=qx(ls -l);
my @the_folder=grep /folder_i_want/, ...
1
vote
1answer
45 views
how to replace IP address on remote host using expect
I wrote the following expect script in order to replace the IP address on remote Linux machine
I use a perl one-liner for this task
I get errors about can't read "HOME": no such variable ,
Please ...
5
votes
1answer
87 views
Execute a command within 'sed'
I have a list of random memory addresses saved in a text file, and I need to sed them out, decode them, and save them back to my file. However, the decoding operation I'm trying to perform is handled ...
1
vote
1answer
80 views
Forcing Bash to use Perl RegEx Engine
As you may already know, a lot of the features modern RegEx engines support (back referencing, lookaround assertions, etc.) are not supported by Bash RegEx engine. Following is a simple Bash script I ...
1
vote
1answer
47 views
fixing cpan by resetting it
So I ran into a simple little problem. This is a somewhat rookie mistake.
I wasn't connected to the internet and started cpan. It started to configure for the first time and then when I realised a ...
0
votes
1answer
41 views
Read and parse XML input via TCP [closed]
I'm setting up something where I'll need to be able to setup a service that accepts input on a TCP port and then parses the XML provided and extracts the necessary data, then posts that to Google's ...
2
votes
6answers
218 views
Repeat each line multiple times
Would like to have each line in a file repeated a fixed number of times.
e.g. have each line repeated four times:
a
b
c
becomes:
a
a
a
a
b
b
b
b
c
c
c
c
I've done some searching, and there are ...
0
votes
2answers
49 views
according root permission to www-data
I have a perl script dhcpmanip.pl which contain this line: system "hostapd /etc/hostapd-1.0/hostapd/hostapd.conf". It's a command to start hostapd and I get this error :
Insecure `$ENV{PATH}` while ...
2
votes
2answers
55 views
How can I use procmail to modify the body of an email and then forward it to an external address?
I'm struggling to get procmail to first transform, and then forward, a received email. Here's what I'd like to do:
:0 f
| ~/bin/encryptemail.pl | mail [email protected]
That is, I want to run the ...
1
vote
1answer
92 views
How to filter an array of strings in ksh
Please advise what's wrong in my ksh code. I want to remove the IP's as defined in "bb" array from "aa" array so the IP's 255.0.0.0 and 255.255.255.0 will be removed from the list in aa array.
When ...
2
votes
2answers
38 views
ksh + delete number from string
the string IP include some IP address numbers
as the following example
echo ${IP[*]}
192.9.200.1 192.9.200.2 192.9.200.3
is it possible to remove some IP address number from the list ( using ksh ...
1
vote
2answers
63 views
perl one liner + how to match IP address that located in the first/sec field of file
the following perl one liner syntax verify if IP address in "$IP" match the IP ADDRESS in file
perl -ne 'BEGIN{$IP=shift} print if /(^|\s)\Q$IP\E(\s|$)/;' $IP file
file have two fields
as the ...
2
votes
2answers
75 views
linux & solaris - separate netmask IP's from ordinary IP's
I have file with IP address and netmask IP's
my target is to cut the netmask IP's from the file_with_IPs.txt and paste them to another file as file_with_only_netmask_ips.txt
remark - netmask IP can ...
-4
votes
4answers
140 views
perl one liner + how to replace any last IP address octets
How to replace any last IP address octets (four octet ) to 0
remark: Implementation should be by Perl one linear on linux machines
for example
192.9.200.124 will replaced to 192.9.200.0
...
4
votes
2answers
71 views
No idea how to troubleshoot Bugzilla email issue
I'm a complete n00b when it comes to Bugzilla (and complex perl applications in general) so don't assume any level of knowledge in that area. If I haven't documented it in this post, assume I haven't ...
1
vote
2answers
92 views
Perl - /etc/shadow - Permission Denied
The following command is being executed by a non root user :
perl -pi -e 's/^an24:/an24:\*LK*/g' /etc/shadow
A permission denied is being issued.
This indicates some privileges issues.
Can such ...
-2
votes
1answer
55 views
Difference between command line argument and giving an input command [closed]
What is the difference between @ARGV and asking the user for input?
$num = $ARGV[0];
and
$_ = <STDIN>;
Either way a user has to put an input isn't it?
How are they different?
-4
votes
1answer
68 views
Usefulness of @ARGV in Perl [closed]
What is the difference between using just normal arrays and the special array (command line argument)?
Normal array: @num(1,2,3,4), and you can use $num[0], etc
Special array: you have to use @ARGV, ...
-2
votes
1answer
41 views
Perl confused with script [closed]
Write a perl script that takes one argument, the name of a file or directory. The script should call the stat function and print the resulting data along with a one line explanation of each field.
my ...
-2
votes
1answer
50 views
Perl Script Explanation [closed]
#!/usr/bin/perl -w
use strict;
my $args;
$args=@ARGV;
if ($args<1)
{
die("Expecting a filename");
}
sub showstat
{
print " $_[0] dev, device number of filesystem\n";
print " $_[1] ...
2
votes
3answers
102 views
I want to find duplicates in a file and add a character to the end of the line on the 1st match
I am trying to find duplicates in a file and once a match is found mark the 1st match with a character or word on the end of the line.
eg my file (test.html) contains the following entries
host= ...
-2
votes
1answer
75 views
Perl only one option at a time [closed]
There is a requirement where I can't put two options at the same time.
For instance with -a option:
file.pl -a file.text # executes file
But if I write
file.pl -a -a file.text # it is ...
3
votes
2answers
75 views
Passing quotes and full strings to bash -c or zsh -c
When I am in Perl and I call system(some_command), this invokes some_command on /bin/sh. I would like it instead to run some_command in another shell such as bash or zsh.
One way of running ...
-3
votes
1answer
64 views
perl script explanation please [closed]
Write a perl program that reads in a text file containing
one word per line. Create a hash containing the words read as
keys and the number of times they have been read as the value.
Print ...
2
votes
3answers
419 views
Easy way to parse syslog date format
I'd like to write a script that analyses the last week's syslog.
But my syslog logs in a stupid date format, e.g. "May 22". If it logged as 2013-05-22, this task would be trivial.
Is there a way ...
3
votes
3answers
99 views
sed + how to remove character/s that start or ended on each number
How do I remove the . character(s) that start in the beginning of each number or end on each number?
Remark – perl one liner also good alternative for sed.
Example input:
.23.12.44.5.
.233.3.3.3
...
1
vote
1answer
76 views
Perl dependency issue
I've installed CentOS 6.3 (i386) recently.
It has two perl binary
/usr/bin/perl (v5.10.1)
/usr/local/appx/perl/bin/perl (v5.8.8)
My question: Is it possible to install some other funtinonality ...
5
votes
2answers
249 views
Special character '#' in Perl SSH command
I try to send command using SSH in my perl script with # but it gets truncated right at #
Example:
Input text is :
$message = "Product ID # STK000134"
The SSH command is :
$execute=`ssh -q ...
6
votes
4answers
506 views
How to remove multiple blank lines from a file?
I have some text-files I use to take notes in - just plain text, usually just using cat >> file. Occasionally I use a blank line or two (just return - the new-line character) to specify a new ...
1
vote
2answers
44 views
Trimming one part if equal to another part?
I use an e-mail quote attribution string like this:
On dd mmm yyyy hh:mm +hhmm, from [email protected] (Example Dot Org):
where [email protected] is the sender's e-mail address and Example Dot Org is ...
0
votes
2answers
104 views
Reordering strings in linux
How can I change lines around using the command line?
e.g. I have these lines:
Acct-Status-Type = Start
User-Name = "37XXXXXXX"
Event-Timestamp = "Apr 12 2013 15:56:55 AMT"
I need to ...
4
votes
3answers
354 views
Delete XML node containing certain element
I want to remove all Placemarks from a KML file that contain the element <tessellate>. The following block should be wholly removed:
<Placemark>
...
-1
votes
3answers
124 views
Sorting IP address according to the second field in file
in my ksh script I need to add the following task ( OS - linux/solaris )
I have the following file
more test.txt
/etc/backup/app 172.1.120 172.110.120
/etc/backup/app 172.1.120.12 ...
0
votes
1answer
68 views
read line by line and take a string in line and assign that string to the subsequent line using perl
Data file is fixed length file, and I want to read file line by line and take a string from the current line, and then append that string to the subsequent line and write into another file.
For ...
-4
votes
1answer
70 views
How to transform two delimited ASCII files
These are 2 common delimited, text file transformation problems I'd like to find scripts to do (I dont know if awk or perl is best for these tasks).
csh is the default shell on my Solaris10 unix ...
0
votes
3answers
65 views
Grep end regex matching
On OS X, system_profiler SPHardwareDataType outputs:
Hardware Overview:
Model Name: MacBook Pro
Total Number of Cores: 4
L2 Cache (per Core): 256 KB
L3 Cache: 8 MB
Memory: 8 GB
I want to ...
2
votes
3answers
201 views
awk, sed, grep, perl… which to print out in this case?
I have this syntax in a file (http response times from analog):
<thead><tr><th class="x">seconds</th><th class="R">reqs</th><th ...
10
votes
2answers
1k views
What does ${1+“$@”} mean in a shell script, and how does it differ from “$@”?
In the Perl documentation, perlrun(1) suggests launching Perl scripts using a bilingual shell/Perl header:
#!/bin/sh
#! -*-perl-*-
eval 'exec perl -x -wS $0 ${1+"$@"}'
if 0;
What does ${1+"$@"} ...

