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
# 8  
Old 05-09-2012
Actually the S means space for i used the word S for space, the original line looks like
In original it contains the blank chracter

---------- Post updated at 12:51 AM ---------- Previous update was at 12:49 AM ----------

@balajesuri The Unix and Perl Guru..
Its not an homework or coursework Actually regularly i receive a file and i have to this manually jo just think to automate it
# 9  
Old 05-09-2012
Modified my code
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/ //g; print $c," Space  " if $c;
print "\n"}' filename

# 10  
Old 05-09-2012
Case can exist this also

Last edited by parthmittal2007; 05-09-2012 at 10:17 AM.. Reason: code tags, see PM
# 11  
Old 05-09-2012
Code:
perl -ne '$a=$b=$c=0;s/^@//;
@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/ //g; print $c," Space  " if $c;
if ($a+$b+$c == 0 ){print "0 0";}print "\n"}' file.txt

# 12  
Old 05-09-2012
But this code is not showing $a1,$b1,$c3...like that
# 13  
Old 05-09-2012
Your input file contain only two line ?
If not not please provide sample input file.
Otherwise use the below code
Code:
 perl -ne 'chomp;if($. == 1){$first=$_;next}$a=$b=$c=0;$first=~s/^@//;
@flds=split(/@/, $first);@var=split(/,/);
foreach (@flds) {
print $var[$j++]," ";$a=($line=$_)=~s/<//g; print $a," LP " if $a;
$b=($line=$_)=~s/>//g;print $b," RP " if $b;
$c=($line=$_)=~s/ //g; print $c," Space  " if $c;
if ($a+$b+$c == 0 ){print "0 0";}print "\n"}' filename


Last edited by pravin27; 05-09-2012 at 08:05 AM..
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