LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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, 11:43 AM   #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 04:38 AM.
 
Old 03-30-2012, 01:32 PM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,009

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

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

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

Rep: Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193
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, 11:43 AM   #5
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,783

Rep: Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214
Note that the string fragment "; " contains two delimiters with a null string between them.
 
1 members found this post helpful.
Old 04-01-2012, 07: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, 01:05 AM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,009

Rep: Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193
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



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 07:24 AM
linux distro question & mysql install question natalie.aloi Linux - Newbie 5 07-19-2009 08:28 PM
Question, Apples Contribution to Open Source + MacOs file structure question Higgy3k Other *NIX 5 07-25-2005 04:23 AM
Not your regular GRUB question - just a short question for a fried MBR!! ziphem Linux - General 3 01-31-2005 01:51 PM
login prompt question & kde scheme question JustinCoyan Slackware 2 06-09-2004 02:02 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:42 AM.

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
Open Source Consulting | Domain Registration