Perl -> Identify Values


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl -> Identify Values
# 1  
Old 02-08-2013
Perl -> Identify Values

Hi,

I tried to find out the users under the file /etc/shadow , where the value should be 90, which shouldn't be less or more than that.. if its more or less, it should give me the output as BAD.

{
print (GOOD);
}
Else
{
print (BAD);
}
# 2  
Old 02-08-2013
Which field? Change n in $F[n] to whichever field you're looking at (field index starts from 0)
Code:
perl -F':' -lane '$F[4] == 90 ? print "Good" : print "Bad"' /etc/shadow

# 3  
Old 02-08-2013
Hi Bala,

I tried like the below, but got the error message as ,

Bad name after F' at OS_linux.pl line 147.

Code:
perl -F':' -lane '$F[4] == 90 ?'
        {
                print "Good" : AD.1.1.1.1 `/etc/shadow`;
}
else
{
                print "Bad" : AD.1.1.1.1 ` /etc/shadow`;
}

Am I missing anything.

Last edited by Franklin52; 02-08-2013 at 04:45 AM.. Reason: Please use code tags for data and code samples
# 4  
Old 02-08-2013
Quote:
Originally Posted by gsiva
perl -F':' -lane '$F[4] == 90 ?'
{
print "Good" : AD.1.1.1.1 `/etc/shadow`;
}
else
{
print "Bad" : AD.1.1.1.1 ` /etc/shadow`;
}
Am I missing anything.
Yeah you're missing a lot of things. This is a very bad perl code!
Could you please explain a bit more as to what you're trying to achieve exactly? Please provide more info on input, desired output...
# 5  
Old 02-08-2013
My apologies as Im not much familer in Perl scripting.

Actually, the script should be checking for the 5th field on /etc/shadow file, whereas the value of the 5th field is 90. Now, the perl script should check for this 90 value, if it doesn't have 90, either its less or more, it should print the output as GOOD or BAD.
THE OUTPUT IS LIKE:
Code:
  {
                 print "GOOD:   /etc/shadow  has the 5th value is 90\n\n";
}
else
        {
                print "BAD:  /etc/shadow does not have 5th value 90\n\n";
}


Last edited by Franklin52; 02-08-2013 at 04:45 AM.. Reason: Please use code tags for data and code samples
# 6  
Old 02-08-2013
Code:
#! /usr/bin/perl -w
use strict;

open FILEHANDLE, "< /etc/shadow";

my $line = "";
my @fields = ();

while ($line = <FILEHANDLE>) {
    chomp($line);
    @fields = split /:/, $line;
    if ($fields[4] == 90) {
        print "$line ====>> Good\n";
    }
    else {
        print "$line ====>> Bad\n";
    }
}

close FILEHANDLE;

# 7  
Old 02-08-2013
Thanks bala,
but, the output is not like expected. its showing out all the contents in the file. I want to get only the BAD and the user name on value 1 on the file /etc/shadow which has the BAD one.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to identify varying unique fields values from a text file in UNIX?

Hi, I have a huge unsorted text file. We wanted to identify the unique field values in a line and consider those fields as a primary key for a table in upstream system. Basically, the process or script should fetch the values from each line that are unique compared to the rest of the lines in... (13 Replies)
Discussion started by: manikandan23
13 Replies

2. Shell Programming and Scripting

Perl to identify specific runs in input and print only lines identified

In the perl one-liner below I am identifying the runs of 6a or 6A in each line starting with >. The code seems close but it prints each > line no matter if it has 6a or 6A in it. Only the line with the 6a or 6A needs to be printed. So using the input file, only the >hg19_refGene_NM_001918_3... (10 Replies)
Discussion started by: cmccabe
10 Replies

3. Shell Programming and Scripting

Identify duplicate values at first column in csv file

Input 1,ABCD,no 2,system,yes 3,ABCD,yes 4,XYZ,no 5,XYZ,yes 6,pc,noCode used to find duplicate with regard to 2nd column awk 'NR == 1 {p=$2; next} p == $2 { print "Line" NR "$2 is duplicated"} {p=$2}' FS="," ./input.csv Now is there a wise way to de-duplicate the entire line (remove... (4 Replies)
Discussion started by: deadyetagain
4 Replies

4. Shell Programming and Scripting

Perl :: reading values from Data Dumper reference in Perl

Hi all, I have written a perl code and stored the data into Data structure using Data::Dumper module. But not sure how to retreive the data from the Data::Dumper. Eg. Based on the key value( Here CRYPTO-6-IKMP_MODE_FAILURE I should be able to access the internal hash elements(keys) ... (1 Reply)
Discussion started by: scriptscript
1 Replies

5. Shell Programming and Scripting

Compare multiple files, identify common records and combine unique values into one file

Good morning all, I have a problem that is one step beyond a standard awk compare. I would like to compare three files which have several thousand records against a fourth file. All of them have a value in each row that is identical, and one value in each of those rows which may be duplicated... (1 Reply)
Discussion started by: nashton
1 Replies

6. Shell Programming and Scripting

Check to identify duplicate values at first column in csv file

Hello experts, I have a requirement where I have to implement two checks on a csv file: 1. Check to see if the value in first column is duplicate, if any value is duplicate script should exit. 2. Check to verify if the value at second column is between "yes" or "no", if it is anything else... (4 Replies)
Discussion started by: avikaljain
4 Replies

7. Shell Programming and Scripting

Perl Script to identify files without extension and assign a value

Hi, I have a perl script which is a part of a shell script which read lines from a flat file(which is generated as part of a script after a series of bteq/fexp) and assigns a value for each object in the file based on the type of file name. (i.e extensions like .bteq/.ctl/.ksh etc) For example,... (1 Reply)
Discussion started by: yohasini
1 Replies

8. Shell Programming and Scripting

Identify function image magick problem - perl

Hi, I got some error when I try to write content from file store into array then for each word that separate by space use identify function to display image information.here is my code #!/usr/bin/perl -w open(FILE,'transfer_file_perl.txt') or die "$!"; my $line = <FILE>;#because it is one... (2 Replies)
Discussion started by: guidely
2 Replies

9. Shell Programming and Scripting

Identify high values "ÿ" in a text file using Unix command

I have high values (such as ÿÿÿÿ) in a text file contained in an Unix AIX server. I need to identify all the records which are having these high values and also get the position/column number in the record structure if possible. Is there any Unix command by which this can be done to : 1.... (5 Replies)
Discussion started by: devina
5 Replies

10. Shell Programming and Scripting

Identify matching data in a file and output to original line, in perl

Hi, I haven't done this for awhile, and further, I've never done it in perl so I appreciate any help you can give me. I have a file of lines, each with 5 data points that look like this: AB,N,ALLIANCEBERNSTEIN HLDNG L.P,AB,N ALD,N,ALLIED CAPITAL CORPORATION,ALD,N AFC,N,ALLIED CAPITAL... (4 Replies)
Discussion started by: Pcushing
4 Replies
Login or Register to Ask a Question