Find and Print in Unix or Perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find and Print in Unix or Perl
# 1  
Old 05-08-2012
Find and Print in Unix or Perl

This is

Last edited by parthmittal2007; 05-09-2012 at 03:32 AM..
# 2  
Old 05-08-2012
The second line is blank, did you mean the third?

What does @ mean?

What are these LP, RP things, and where do they come from?
# 3  
Old 05-09-2012
It means for the first @the value of $a will come for the second @ the value of $b will come..I hope you understand.

Actually There is Pre defined formatting and i have to follow.Mean to say $a is 11 left padded, $b is 2 right padded...

Its by mistake i there is space in second line. You should consider the third line at place of second line

---------- Post updated at 10:38 PM ---------- Previous update was at 12:36 PM ----------

So the output is expected is
$a LP 11
$b RP 2
$c LP 19 Space 5
....like this


---------- Post updated at 11:12 PM ---------- Previous update was at 10:38 PM ----------

any idea
# 4  
Old 05-09-2012
Could you post what the output would actually look like, instead of inserting nonsense like RP and LP that doesn't actually belong in the output? Or if it's not nonsense, explain where it comes from. Use code tags to get the proper alignment.
# 5  
Old 05-09-2012
In most brief way i want the space count between two @ The two @ are either filled with < OR > or S(space)

so the output expected is
Code:
 LP 5
RP 6
like this


Last edited by parthmittal2007; 05-09-2012 at 03:32 AM..
# 6  
Old 05-09-2012
Code:
[root@host dir]# cat>test.pl
#! /usr/bin/perl -w
use strict;

my ($count, $line, @x, $padChar, $arrCnt);

open I, "< input";
for $line (<I>) {
    chomp ($line);
    $count = ($line =~ tr/@/@/);
    @x = (chr(97)..chr(97+$count-1));
    $arrCnt = 0;
    while ($line =~ /@([^@]+)/g) {
        $padChar = $1;
        if ($padChar =~ /^<+$/) {
            print "\$$x[$arrCnt] LP ", length($padChar), "\n";
            $arrCnt++;
        }
        elsif ($padChar =~ /^>+$/) {
            print "\$$x[$arrCnt] RP ", length($padChar), "\n";
            $arrCnt++;
        }
        elsif ($padChar =~ /^<+S+$/) {
            print "\$$x[$arrCnt] LP ", ($padChar=~tr/</</), " Space ", ($padChar=~tr/S/S/), "\n";
            $arrCnt++;
        }
        elsif ($padChar =~ /^>+S+$/) {
            print "\$$x[$arrCnt] RP ", ($padChar=~tr/>/>/), " Space ", ($padChar=~tr/S/S/), "\n";
            $arrCnt++;
        }
    }
}
close I;
[root@host dir]#
[root@host dir]# cat input
@<<<<<<<@>>@>>>>>>>>>>SSS@<<<<<<<<<<<<<<@<<<<<<<<@<<<<<<<@<<<<<<<@<<<<<<<<<<<<<<<<<<<<<<<<@<<<<<<<<<<<<<<SSS
[root@host dir]# ./test.pl
$a LP 7
$b RP 2
$c RP 10 Space 3
$d LP 14
$e LP 8
$f LP 7
$g LP 7
$h LP 24
$i LP 14 Space 3
[root@host dir]#

Is this homework/coursework/college project work?
# 7  
Old 05-09-2012
How about this ?
Code:
perl -ne '$a=$b=$c=0;
@flds=split(/@/);
foreach (@flds) {
$a=($line=$_)=~s/<//g; print $a," LP " if $a;
$b=($line=$_)=~s/>//g;print $b," RP " if $b;
$c=($line=$_)=~s/S//g; print $c," Space  " if $c;
print "\n"}' Filename

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

perl lwp find word and print next word :)

hi all, I'm new there, I'm just playing with perl and lwp and I just successfully created a script for log in to a web site with post. I have a response but I would like to have something like this: I have in my response lines like: <div class="sender">mimi020</div> <some html code.....>... (3 Replies)
Discussion started by: vogueestylee
3 Replies

2. Shell Programming and Scripting

Character Find and replace in Unix or Perl

Hi, I am stuck with an problem and want some help, what i want to do is There is a directory name temp which include file named t1.txt, t2,txt, t3.txt and so on. These files contains data, but there are some bad character also that is % present in the files , I want to write the script... (13 Replies)
Discussion started by: parthmittal2007
13 Replies

3. Shell Programming and Scripting

find: missing argument to `-exec' while redirecting using find in perl

Hi Friends, Please help me to sort out this problem, I am running this in centos o/s and whenever I run this script I am getting "find: missing argument to `-exec' " but when I run the same code in the command line I didn't find any problem. I am using perl script to run this ... (2 Replies)
Discussion started by: ramkumarselvam
2 Replies

4. Shell Programming and Scripting

Perl :How to print the o/p of a Perl script on console and redirecting same in log file @ same time.

How can i print the output of a perl script on a unix console and redirect the same in a log file under same directory simultaneously ? Like in Shell script, we use tee, is there anything in Perl or any other option ? (2 Replies)
Discussion started by: butterfly20
2 Replies

5. Shell Programming and Scripting

Perl : find perl executable binary

Hi I have an oracle perl script running as cron job across multiple unix servers. The issue is the perl binary is found in multiple directories I use in the start of the script ... #!/usr/bin/perl on some servers the script fails because /usr/bin/perl is not present. Is there a way i can... (4 Replies)
Discussion started by: PrasannaKS
4 Replies

6. Shell Programming and Scripting

Perl : Find a string and Print full line

Hi Need a perl script to read lines in a file, scan for a string named "APPLE" and write to different file the only lines containing the matched string. (5 Replies)
Discussion started by: PrasannaKS
5 Replies

7. Shell Programming and Scripting

Unix help to find blank lines in a file and print numbers on that line

Hi, I would like to know how to solve one of my problems using expert unix commands. I have a file with occasional blank lines; for example; dertu frthu fghtu frtty frtgy frgtui frgtu ghrye frhutp frjuf I need to edit the file so that the file looks like this; (10 Replies)
Discussion started by: Lucky Ali
10 Replies

8. Shell Programming and Scripting

Perl ? - How to find and print the lowest and highest numbers punched in by the user?

. . . . . . (3 Replies)
Discussion started by: some124one
3 Replies

9. HP-UX

Print Problem in UNIX. Need to know the option to specify the print paper size

Hi, Could any one please let me know what is the option available in UNIX to print by specifying the paper size? We are using Unix11i. I could n't see any option specified in the 'lp' command to print the report by specifying the size of the paper. It would be of great help to me, if... (1 Reply)
Discussion started by: ukarthik
1 Replies

10. UNIX for Dummies Questions & Answers

Unix find command to print directory and search string

Hi i need to print pathname in which the string present using 'find' command sample output like this Pathname String to be searched ---------- -------------------- /usr/test/myfile get /opt/test/somefile get Thanks in... (4 Replies)
Discussion started by: princein
4 Replies
Login or Register to Ask a Question