finding first instance


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers finding first instance
# 15  
Old 08-13-2002
You don't really need the max at all. It is effectively doing nothing in your script anyway as you are only taking substrings from 1-9. If theres more than your 'max' it won't grab them, and if there's less than max - you've not acheived anyting by having it. So just skip it alltogether.

Of course if your offsets are changing ...that's a hassle for you.

instead of these 3 lines....
max=11;
line=substr($0,0,max) ;
firstcol=substr(line,0,3) ;

just use => firstcol=substr($0,0,3) ;

etc.
# 16  
Old 08-13-2002
Hey yes Peter.. its perfectly working...

Then this $0 contains the whole record is it??? or

Does it point to the starting position of the record???


Thanks,
Nisha
# 17  
Old 08-13-2002
Quote:
Originally posted by peter.herlihy
You understand it perfectly...and I would guess you could see the importance of sorting the file before you start this too.
Ha!

My perl code doesn't require the input to be sorted!

[Dances around the office doing the "Nanny Nanny Boo Boo" Song]

Actually, that's not entirely true, as long as you don't care about the last parameter. It might be out of sync due to not being sorted. Smilie
# 18  
Old 08-13-2002
Nisha, $0 is the entrire record.

Aus, Here's my equivalent in awk of your hash in perl. (nah nah na nah nah) - look mum - no sort! The awk associative array (hash). With a few more bells and whistles. ( This one is in use).

/^[^|]*\|[Ss][Ee]/
{
key=$5 $6; edd = x[key];
if ( edd !~ /^[0-9][0-9][0-9][0-9]$/)
{ edd = substr($18,5,2) substr($18,3,2) ; x[key]=edd } ;
print $1,$2,$3,$4,$5,edd,$6,$7,$8,$9,$13,$14,$15,$16,$17,$18
}
# 19  
Old 08-14-2002
Quote:
Originally posted by peter.herlihy
Aus, Here's my equivalent in awk of your hash in perl. (nah nah na nah nah) - look mum - no sort! The awk associative array (hash). With a few more bells and whistles. ( This one is in use).
<KungFuMovie>Huh? You may have defeated me with your Southern Hemisphere AwkFu coding style, but my Northern Hemisphere PerlFu coding style is easier to read! I'll get you next time! Ha!Ha!Ha!</KungFuMovie>

I'll remeber this next time I need to do some slicing and dicing in awk. I usually save the simple list processing for awk and the more logic ridden probelms stuff for perl. I have gotten a lot of good stuff out of awk in the past.
# 20  
Old 08-14-2002
Hey Pet,

Now what????? I thought i got clarified and u have inserted a new stuff and as auswipe says its tough to decifer...

U both have to take the responsibility of explaining it to me Smilie


Lots of learning.. uhhhhhhhhhhhhh
# 21  
Old 08-14-2002
This thread is getting way too big.... and I'm geeing way too busy...if you're really that keen to understand the awk associative array - then start a thread. I'm gonna close this one.

And Aus - I'd probably use Perl too - if I knew how...just learning it.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Grep the only instance name

Hi, I want to get the only application name from the server. Ex: if i give $ ps -ef | grep bw. It will show all BW process with entire path. It will little confuse to list out the process. Can anyone have syntax to get only the instance name. I need this for be, hawk,ems also. Please... (2 Replies)
Discussion started by: ckchelladurai
2 Replies

2. Shell Programming and Scripting

Keep the last instance of the record

Hi All, I have a input file like 1| abc 1| abcd 1| abcde 2| abc 2| abcd 3| abcde I want the output like 1| abcde 2| abcde Any help would be highly appreciated. Thanks in advance. (9 Replies)
Discussion started by: lrkp
9 Replies

3. Red Hat

Apache instance

Hi , Maximum How many instances of apache can we run in one box? (2 Replies)
Discussion started by: krish4linux
2 Replies

4. Shell Programming and Scripting

What does : do in this instance

Guys please see below functions to return a status depending on user input. Both seem to work the same. The second way has a : line which i can't understand or see in a ksh manual anywhere. Instead of doing the variable change if its empty on this line the first function simply does it on the... (7 Replies)
Discussion started by: lavascript
7 Replies

5. Shell Programming and Scripting

matching first instance of FS

Hi All, I have a property in a file as: property=value=a If I use FS="=" then I want only first = to be considered as field separator and remaining as value echo -e "property=value=a" | awk -F= '{print $2}' ie my $2 should be value=a Can anyone please help me with this. I need it in... (3 Replies)
Discussion started by: gurukottur
3 Replies

6. Shell Programming and Scripting

replace first instance(not first instance in line)

Alright, I think I know what I am doing with sed(which probably means I don't). But I cant figure out how to replace just the first occurance of a string. I have tried sed, ed, and grep but can't seem to figure it out. If you have any suggestions I am open to anything! (3 Replies)
Discussion started by: IronHorse7
3 Replies

7. Shell Programming and Scripting

finding duplicate files by size and finding pattern matching and its count

Hi, I have a challenging task,in which i have to find the duplicate files by its name and size,then i need to take anyone of the file.Then i need to open the file and find for more than one pattern and count of that pattern. Note:These are the samples of two files,but i can have more... (2 Replies)
Discussion started by: jerome Sukumar
2 Replies

8. Shell Programming and Scripting

Single Instance

Hi, I have a script. I want only one instance of the script to be running at any point of the time. How can I do it. what would be the exact format of the ps command for doing this. For example the name of my script is "Inst.sh" Thanx in advance (2 Replies)
Discussion started by: sendhil
2 Replies

9. Linux

OTRS instance

hi frnds here i m trying to configure OTRS instance but i m getting the following error message while runnning through browser. I m writing the following http://192.168.1.55:8080/otrs2/index.pl " #!/usr/bin/perl -w... (7 Replies)
Discussion started by: naik_mit
7 Replies

10. UNIX for Dummies Questions & Answers

Copy Db Instance

I need to copy my Live Db Instance to my Test Db Instance Can somebody please tell me the easiest way to go about this It is an Informix Database running on HP-UX Thanks (0 Replies)
Discussion started by: cobdeng
0 Replies
Login or Register to Ask a Question