LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-30-2012, 12:43 PM   #1
Trd300
Member
 
Registered: Feb 2012
Posts: 89

Rep: Reputation: Disabled
Else if or not else if ? That is the question.


%%%%%

Last edited by Trd300; 05-01-2012 at 05:38 AM.
 
Old 03-30-2012, 02:32 PM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,425

Rep: Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826
Have you printed all the values you are using? ie. all the values stored in each array?
 
Old 03-30-2012, 11:29 PM   #3
Trd300
Member
 
Registered: Feb 2012
Posts: 89

Original Poster
Rep: Reputation: Disabled
%%%%%

Last edited by Trd300; 05-01-2012 at 05:39 AM.
 
Old 03-31-2012, 12:34 PM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,425

Rep: Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826
Would appear you get different results to me:

Altered code:
Code:
#!/usr/bin/awk -f

BEGIN{ FS = OFS = "|" }

$1 == "" || $1 ~ / +/ && $2 == "" || $2 ~ / +/ {
    f3 = f4 = ""

    split($2,c2,"[ ;]")

    print c2[2],c2[3],c2[5],c2[6]
    a = split($1,c1," *; *")

    for( i = 1; i <= a; i++){
	split(c1[i], b, " ")

	print b[2],b[3]
	if ( b[2] >= c2[2] && b[3] <= c2[3] )
	    f3 = f3 (f3?"; ":"")c1[i]
	if ( b[2] >= c2[5] && b[3] <= c2[6] )
	    f4 = f4 (f4?"; ":"")c1[i]

    }

    $3 = f3
    $4 = f4

}
1
On running:
Code:
$ ./test.awk file
10|20|bb_b|20
12|18
23|27
aa_a 12 18; aa_a 23 27|bb_b 10 20; bb_b 20 30|aa_a 12 18|
The results in red would appear to be an issue?
 
1 members found this post helpful.
Old 04-01-2012, 12:43 PM   #5
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 3,136

Rep: Reputation: 1349Reputation: 1349Reputation: 1349Reputation: 1349Reputation: 1349Reputation: 1349Reputation: 1349Reputation: 1349Reputation: 1349Reputation: 1349
Note that the string fragment "; " contains two delimiters with a null string between them.
 
1 members found this post helpful.
Old 04-01-2012, 08:43 PM   #6
Trd300
Member
 
Registered: Feb 2012
Posts: 89

Original Poster
Rep: Reputation: Disabled
Thanks grail !
Thanks rknichols !

I didn't know it counted the empty string between ";" and " ".

I just had to increment the indices of the second part by +1 and it works of course !

Thanks guys !
 
Old 04-02-2012, 02:05 AM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,425

Rep: Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826
Actually the null is not an issue, but rather your split as it says split on either " " OR ";" so as there is more than one of these in the middle it caused an issue.
Simply try adding "+" to your regex as it needs to have one or more of those as a separator.
Code:
split($2,c2,"[ ;]+")
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
basic html question - download link to files on my webpage question Davno Linux - Server 5 12-25-2009 08:24 AM
linux distro question & mysql install question natalie.aloi Linux - Newbie 5 07-19-2009 09:28 PM
Question, Apples Contribution to Open Source + MacOs file structure question Higgy3k Other *NIX 5 07-25-2005 05:23 AM
Not your regular GRUB question - just a short question for a fried MBR!! ziphem Linux - General 3 01-31-2005 02:51 PM
login prompt question & kde scheme question JustinCoyan Slackware 2 06-09-2004 03:02 PM


All times are GMT -5. The time now is 06:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration