Perl One Liner To Delete Line In Csv File If One Columns Is Toobig

I have a little bash script that cats out a file and tells me if there is a line
where the 11th column has more than 6 characters in it.
It emails me where there is a bad line in a file - bead meaning that it will break a
donwstream process.

anyhow when i get the email saying that there is a bad file i just log in to the pc via
vpn and the I sed out the lines from the file that I get in the email. The bad lines are
always in danny.csv not danny1.csv
It has been the same lines killing the downstream process for a few weeks, so i put the "sed -i's" into
the script and it does it automagically.

[CODE]
for i in danny.csv danny1.csv
do
cat /come/and/play/with/$i | perl -ne 'print if length((split /,/)[10]) > 6' | mail -s "danny.csv bad line" casper@casperr.com
done

#it would be nice to find a perl change the file in place
sed -i '/D,642,0642,UBF,EVL,,M,,S,S,FOREVER,213,213,/d' /come/and/play/with/us/danny.csv
sed -i '/D,642,0642,UBF,EVL,,M,,S,S,QSP-U=C,4,4,/d' /come/and/play/with/us/danny.csv
[CODE]

However when a new line gets put into this file, I am going to have to log in and take out the line.
SO I have been trying to write a perl one liner that will edit the file in place, like sed, and make a
backup of the file. I just need a perl one liner that will delete any line where the 11th columns has more
than 6 characters in it.
[CODE]
perl -p -i.bak -e 's/\,\w{7}\,//g - which does not work.
[CODE]
I tried something like this:

[CODE]
perl -nle 'print if /\,\w{7}\,/' /come/and/play/with/us/danny.csv
[CODE]
but that does not catch the QSP-U=C and it catches more lines than just the
FOREVER. for a solutinog I need to focus on the the 11th column.


Similar Content



Need Help In Bash Scripting

I have two files which has exact same number of lines.
I want first line of first file should be filename of new file and content of this new file should be first line of second file.
Then second line of first file should be filename of again new file and content of this new file should be second line of second file.
then third line of first file should be filename of again new file and content of this new file should be third line of second file.
and so on...
I am trying to do it using for loop but I am not able to create two for loops.
This is what I have done
Code:
IFS=$'\n'
var=$(sed 's/\"http\(.*\)\/\(.*\).wav\"\,\".*/\2/g' 1797.csv) # filenames of all files
var2=$(sed 's/\"http\(.*\)\/\(.*\).wav\"\,\"\(.*\)\"$/\3/g' 1797.csv) # contents of all files
for j in $var;
do
#Here I do not know how to use $var2
done

Please help.

Remove Lines That Are Subsets Of Other Lines In File

Hello everyone,


Although it seems easy, I've been stuck with this problem for a moment now and I can't figure out a way to get it done.

My problem is the following:

I have a file where each line is a sequence of IP addresses, example :

Line 1: 10.0.01 10.0.0.2
Line 2 : 10.0.0.5 10.0.0.1 10.0.0.2
...

What I'd like to do, is to remove lines that are completely matched in other lines. In the previous example, "Line 1" would be deleted as it is contained in "Line 2".

So far, I've worked with python and set() objects to get the job done but I've got more than 100K lines and sets lookups are becoming time consuming as the program goes :/

Thanks for you help

Extract Middle Of File - How To Strip Header/footer

I have a log file with a header (which I can skip with awk), and a footer, which I need to find a way to remove. The goal is to extract the middle lines from a file. Specifically, there is a header (1 line) and a footer (1 line).
The only way I can figure out how to do this is if I already know how many lines are in the file to begin with. For example, if the file looks like this: line 1 (header)
line 2 (interesting line)
line 3 (interesting line)
line 4 (footer)
I just want to extract the middle "interesting lines" without the header/footer lines.
I can't use grep to remove the header/footer, because I don't know what those lines will contain, only that they exist and are exactly 1 line each. In general, I don't know how many lines are in the file.

How To Install Perl Module On RHEL?

Hello,

I need to install perl-Expect, so, I executed:

Code:
#  yum install -y perl-Expect
Error: Package: perl-Expect-1.21-14.el7.noarch (epel)
           Requires: perl(IO::Pty) >= 1.03
Error: Package: perl-Expect-1.21-14.el7.noarch (epel)
           Requires: perl(IO::Tty)

Okay, I need to install perl(IO::Pty)

I launched
Code:
# yum install -y "perl(IO::Pty)"
No package perl(IO::Pty) available.
Error: Nothing to do

So, how to install all required perl modules to the RHEL?

Disable Warning Messages In Perl..

Hi All,

I'm not a perl programmer, so please help me to disable warning messages. I tried like commenting 'use strict' and 'use warning' in perl program. But it is not working.

All I want is to disable warning messages.

Please note its not actual ping program, But a perl wrapper for ping to display ping output in color (Cope).

Below is output:

Code:
$ ./ping google.com
given is experimental at /usr/local/share/perl/5.20.2/App/Cope.pm line 255.
when is experimental at /usr/local/share/perl/5.20.2/App/Cope.pm line 256.
when is experimental at /usr/local/share/perl/5.20.2/App/Cope.pm line 259.
when is experimental at /usr/local/share/perl/5.20.2/App/Cope.pm line 262.
given is experimental at /usr/local/share/perl/5.20.2/App/Cope/Extra.pm line 119.
when is experimental at /usr/local/share/perl/5.20.2/App/Cope/Extra.pm line 120.
given is experimental at /usr/local/share/perl/5.20.2/App/Cope/Extra.pm line 159.
when is experimental at /usr/local/share/perl/5.20.2/App/Cope/Extra.pm line 160.
when is experimental at /usr/local/share/perl/5.20.2/App/Cope/Extra.pm line 161.
PING google.com (173.194.36.4) 56(84) bytes of data.
64 bytes from bom04s01-in-f4.1e100.net (173.194.36.4): icmp_seq=1 ttl=57 time=67.8 ms
64 bytes from bom04s01-in-f4.1e100.net (173.194.36.4): icmp_seq=2 ttl=57 time=68.1 ms
64 bytes from bom04s01-in-f4.1e100.net (173.194.36.4): icmp_seq=3 ttl=57 time=66.6 ms
64 bytes from bom04s01-in-f4.1e100.net (173.194.36.4): icmp_seq=4 ttl=57 time=66.6 ms
^C
--- google.com ping statistics ---
4 packets transmitted, 4 received, 0 packet loss, time 3004ms
rtt min/avg/max/mdev = 66.687/67.353/68.155/0.743 ms

Works fine when error redirected to /dev/null
Code:
$ ./ping google.com 2>/dev/null
PING google.com (173.194.36.1) 56(84) bytes of data.
64 bytes from bom04s01-in-f1.1e100.net (173.194.36.1): icmp_seq=1 ttl=57 time=68.4 ms
64 bytes from bom04s01-in-f1.1e100.net (173.194.36.1): icmp_seq=2 ttl=57 time=66.6 ms
64 bytes from bom04s01-in-f1.1e100.net (173.194.36.1): icmp_seq=3 ttl=57 time=66.4 ms
^C
--- google.com ping statistics ---
3 packets transmitted, 3 received, 0 packet loss, time 2003ms
rtt min/avg/max/mdev = 66.419/67.179/68.421/0.885 ms

Unfortunately, I cannot use output error redirection because all the perl programs are in PATH.

Actual ping perl program:
Code:
#!/usr/bin/env perl
use App::Cope;
use App::Cope::Extra qw[ping_time percent_b];
use Regexp::Common qw[net];

sub process {

  # header
  line qr{^PING (\S+)} => 'blue bold underline';

  # ping replies
  line qr{time=([0-9.]+ ms)\b}    => \&ping_time;
  mark qr{\($RE{net}{IPv4}\)}     => 'blue';
  line qr{(?:icmp_seq|ttl)=(\d+)} => 'bold';
  line qr{^(?:\d+ bytes )?[Ff]rom ([^:\s]+)} => 'blue bold';

  # final ping statistics
  line qr{(\d+% packet loss)} => \&{ percent_b 0, 1, 26 };
  line qr{min/avg/(?:max/mdev|ewma/max)\s=\s
	  ([0-9.]+)/    # minimum
	  ([0-9.]+)/    # average
	  ([0-9.]+)/    # maximum or moving average
	  ([0-9.]+\sms) # mean deviation or maximum
       }x => ( \&ping_time ) x 4;

}

run( \&process, real_path, @ARGV );

Code:
$ head -n15 /usr/local/share/perl/5.20.2/App/Cope.pm
#!/usr/bin/env perl
package App::Cope;
#use strict;
#use warnings;
use 5.010_000;
use Carp;

our $VERSION = '0.99';

=head1 NAME

App::Cope - Functions for the B<cope> program

=head1 SYNOPSIS

Code:
$ head -n15 /usr/local/share/perl/5.20.2/App/Cope/Extra.pm
#!/usr/bin/env perl
package App::Cope::Extra;
#use strict;
#use warnings;
use 5.010_000;

=head1 NAME

App::Cope::Extra - Pre-defined highlighting syntax for common patterns

=head2 SYNOPSIS

  use App::Cope::Extra;

  line qr{User: (\S+)} => \&{ user 'yellow' };

Thanks

Perl Script Not Running Via Cron

Hi All,

I have perl script which I am trying to run on 1st Monday via cron job.
So I scheduled it as follows:

0 0 1-7 * * root ["$(date '+%a')" = "Mon"] && /usr/bin/perl script.pl

But then it didn't run so checked cron log and it seemed like its missing the command. so added a \ in front of %a and then it picked up the whole command as per cron log.

But still it didnt ran the script. I then change the script to just && echo "test">/tmp/test

Still nothing. if I run it as /usr/bin/perl script.pl it runs though

Thanks in advance.

Checking Presence Of A File Identified/ Addressed By A Variable

hi,

I am newbie in Linux shell scripting.Can anybody help me to check the presence of file identified by variable in Shell scripting?

For example: I am reading the content of a file using while command as below:
"while read -r line
do
code block
done < file_name"

Now in this case every line in file gets stored in the variable 'line' one by one.Problem here is every line in the file is nothing but the file_path of another file say xyz.txt and I am checking presence of this xyz.txt file using below command:
if [-f $line]
as 'line' is the variable which stores file path of xyz.txt but it is not working. It is unable to check the presence of this xyz.txt file as i am addressing it with the variable 'line'.

Please help me.Thanks in advance.

*** ERROR: PERL Module Apache::DBI Is Not Installed !

Hello,

I am configuring OCS Server using the following two documentations:

http://wiki.centos.org/HowTos/OCSNG
http://www.howtoforge.com/how-to-ins...-on-centos-5.5

Getting below error during installaton:

""Checking for DBI PERL module...
Found that PERL module DBI is available.
Checking for Apache:BI PERL module...
*** ERROR: PERL module Apache:BI is not installed !
Checking for DBD::mysql PERL module...
Found that PERL module DBD::mysql is available.
Checking for Compress::Zlib PERL module...
Found that PERL module Compress::Zlib is available.
Checking for XML::Simple PERL module...
Found that PERL module XML::Simple is available.
Checking for Net::IP PERL module...
Found that PERL module Net::IP is available.
*** ERROR: There is one or more required PERL modules missing on your computer !
Please, install missing PERL modules first.""

i have googled for the solution unsuccessfully.
please help me in installing the missing perl module.

thanks in advance..

--
Anil Anji

Syntax Error: Unexpected End Of File

Hi!
I wrote a script shell about changing IP of the httpd.conf from text file and saving a new httpd.conf file for all IPs in the text file. The code is below, Im using mremote on windows (RHEL Release 5.7), and getting this error:
./script1.sh: line 19: syntax error: unexpected end of file

Please help me about that error. Thanks!

(ps: line 19 is the last line in the code => done < "$filename" )

#!/bin/bash

DATE='date +%Y%m%d_%H:%M:%S'
NAME=httpd_ip_change
EXTENSION=conf
max=10

filename="$1"
while read -r line

for ((i=2; i<=$max; ++i ))

do
touch $NAME$i.$EXTENSION.$DATE

sed "s/<VirtualHost 10.11.92.81:80>/$line/g" ./httpd.conf > $NAME$i.$EXTENSION.$DATE

done < "$filename"

Extract Info And Find/count Strings From Blocks Inside Text File

Hello

I have a text file which has blocks like
Code:
dir1/dir2/dir3/name_run_number1:
line1_run_number1_part1
line2_run_number1_part2
line3_run_number1_part3...

Each block is separated with a blank line and there is the ":" in the "header" of each one while each block carries the same "number1" after "run_" suffix
What I want to do is for each block, extract the "number1" as shown in the first line and then for the lines below count from 1-20 and give a message if a "partX" line is missing. Any bash or python would be fine

Thanks