Perl -> Identify Values


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl -> Identify Values
# 8  
Old 02-08-2013
Quote:
Originally Posted by gsiva
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.
Quote:
Originally Posted by gsiva
I want to get only the BAD and the user name on value 1 on the file /etc/shadow which has the BAD one.
Your requirements contradict each other.

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

# 9  
Old 02-12-2013
Hi Bala,

Thanks for your input:
As per your code, the output is like :

Quote:
Bad entries:
But, the output what expected is as below:

Quote:
BAD: ID=gsiva doesn't have the 5th value 90 in /etc/shadow:
else it should be declare as GOOD. Hope it makes sense.
# 10  
Old 02-13-2013
@gsiva: I'm still not able to understand your very specific (and contradicting) requirements.

And by now from all previous posts, you sure do have enough tools equipped to make minor modifications to the code yourself, to suit your requirement. Go ahead, give it a try and let us know what you have brewed :-)
# 11  
Old 02-13-2013
Quote:
Originally Posted by gsiva
...
But, the output what expected is as below:
Code:
BAD: ID=gsiva doesn't have the 5th value 90 in /etc/shadow:

...
The message does not tell you what the 5th value is exactly. We know that it is not 90, but is it 89 or 91 or 100 or something else? Maybe you want to see it; maybe you don't. But I'll assume that you do.

Quote:
Originally Posted by gsiva
...

else it should be declare as GOOD. Hope it makes sense.
The message "GOOD" does not tell you what the ID was in the line you read. You'd simply see the text "GOOD" per line if all lines satisfy the condition. Maybe you want to see the ID; maybe you don't. But I'll assume that you do.

Given these criteria, a short script could be like this:

Code:
awk -F: '{
           if ($5==90) {
             print "GOOD: ID="$1,"has the 5th value 90 in /etc/shadow"
           } else {
             print "BAD: ID="$1,"does not have the 5th value 90 in /etc/shadow. It has",$5,"instead."
           }
         }' /etc/shadow

- Modify the print function in the "else" branch if you don't want to view the bad value.
- Modify the print function in the "if" branch if you only want to see "GOOD"
- Remove the "else" branch completely if you only want to test for and print good lines.
- Remove the "if" branch completely and change the "else" branch to a converse "if" branch if you only want to test for and print bad lines.

tyler_durden
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