Sponsored Content
Operating Systems Solaris Split file based on multi valued attributes Post 302492402 by snukala on Monday 31st of January 2011 09:19:36 AM
Old 01-31-2011
Hi,
Thanks for responding.
The later part of the script,ie, the section under for seems to be failing.
I used the following script.
Code:
#!/bin/awk -f
i=0
awk 'BEGIN{RS=",";FS="\n"}{print $1}' a.txt | sed 's/;/ /g' >> b.txt
while read str;do
    eval array${i}=$str
    i=`expr $i + 1`
    echo $i
done < b.txt
for a in $array0;do
        for b in $array1;do
                for c in $array2;do
                        for d in $array3;do
                                for e in $array4;do
                                        for f in $array5;do
                                        echo $a,$b,$c,$d,$e,$f
                                done
                        done
                done
          done
     done
done

could you plz suggest why is it failing in the or loop.

Regards
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 01-31-2011 at 10:54 AM.. Reason: code tags, Please!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to split file based on subtitle

Hi, unix Gurus, I want to split file based on sub_title. for example: original file fruit apple watermelon meat pork fish beef expected result file file1 fruit apple watermelon file2 meat pork fish beef. (4 Replies)
Discussion started by: ken002
4 Replies

2. Shell Programming and Scripting

bash: How to split up a file based on another?

I've got these 2 files, FILE.txt and SPLIT_BY.txt: FILE.txt contents: FILE01 FILE02 FILE03 FILE04 FILE05 FILE06 FILE07 FILE08 FILE09 FILE10 FILE11 FILE12 FILE13 FILE14 FILE15SPLIT_BY.txt contents: 2 5 (4 Replies)
Discussion started by: byte711
4 Replies

3. UNIX for Dummies Questions & Answers

Filtering maximum valued file.

Hi a.123 a.136 a.146 B.124 B.39 C.24 I have the files in above format ; I want to list out the files which has maximum value in each group as pipe delimited : a.146|B.124|C.24 Please help me in this. Thanks (1 Reply)
Discussion started by: pandeesh
1 Replies

4. Shell Programming and Scripting

Split the file based on the content

Arun kumar something somehting Enterting in to the line . . . . Some text text Finshing the sentence Some other text . . . . Again something somehting Enterting in to the line . . . . . . Again text text Finshing the sentence (6 Replies)
Discussion started by: arukuku
6 Replies

5. Shell Programming and Scripting

Split file based on size

Hi Friends, Below is my requirement. I have a file with the below structure. 0001A1.... 0001B1.. .... 0001L1 0002A1 0002B1 ...... 0002L1 .. the first 4 characters are the sequence numbers for a record, A record will start with A1 and end with L1 with same sequence number. Now the... (2 Replies)
Discussion started by: diva_thilak
2 Replies

6. Shell Programming and Scripting

Multi-line filtering based on multi-line pattern in a file

I have a file with data records separated by multiple equals signs, as below. ========== RECORD 1 ========== RECORD 2 DATA LINE ========== RECORD 3 ========== RECORD 4 DATA LINE ========== RECORD 5 DATA LINE ========== I need to filter out all data from this file where the... (2 Replies)
Discussion started by: Finja
2 Replies

7. UNIX for Dummies Questions & Answers

Split file based on column

i have file1.txt asdas|csada|130310|0423|A1|canberra sdasd|sfdsf|130426|2328|A1|sydney Expected output : on eaceh third and fourth colum, split into each two characters asdas|csada|13|03|10|04|23|A1|canberra sdasd|sfdsf|13|04|26|23|28|A1|sydney (10 Replies)
Discussion started by: radius
10 Replies

8. Shell Programming and Scripting

Split File based on different conditions

I need to split the file Conditions: Ignore any record that either starts with 1 or 9 Split the file at position 404 , if position 404 is abc or def then write all the records in a file > File 1 , the remaining records should go in to a file > File 2 Further I want to split the... (7 Replies)
Discussion started by: protech
7 Replies

9. UNIX for Advanced & Expert Users

Split one file to many based on pattern

Hello All, I have records in a file in a pattern A,B,B,B,B,K,A,B,B,K Is there any command or simple logic I can pull out records into multiple files based on A record? I want output as File1: A,B,B,B,B,K File2: A,B,B,K (9 Replies)
Discussion started by: deal1dealer
9 Replies

10. Shell Programming and Scripting

To Split the file based on column value

Hi Team, I have a requirement in such a way that need to split the file into two based on which column particular value appears.Please find my sample file below. Lets consider the delimiter of this file as either comma or two colons.(:: and ,). So I need to split the file in such a way that all... (2 Replies)
Discussion started by: ginrkf
2 Replies
ARRAY_UDIFF(3)								 1							    ARRAY_UDIFF(3)

array_udiff - Computes the difference of arrays by using a callback function for data comparison

SYNOPSIS
array array_udiff (array $array1, array $array2, [array $...], callable $value_compare_func) DESCRIPTION
Computes the difference of arrays by using a callback function for data comparison. This is unlike array_diff(3) which uses an internal function for comparing the data. PARAMETERS
o $array1 - The first array. o $array2 - The second array. o $value_compare_func - The callback comparison function. The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second. int callback (mixed $a, mixed $b) RETURN VALUES
Returns an array containing all the values of $array1 that are not present in any of the other arguments. EXAMPLES
Example #1 array_udiff(3) example using stdClass Objects <?php // Arrays to compare $array1 = array(new stdclass, new stdclass, new stdclass, new stdclass, ); $array2 = array( new stdclass, new stdclass, ); // Set some properties for each object $array1[0]->width = 11; $array1[0]->height = 3; $array1[1]->width = 7; $array1[1]->height = 1; $array1[2]->width = 2; $array1[2]->height = 9; $array1[3]->width = 5; $array1[3]->height = 7; $array2[0]->width = 7; $array2[0]->height = 5; $array2[1]->width = 9; $array2[1]->height = 2; function compare_by_area($a, $b) { $areaA = $a->width * $a->height; $areaB = $b->width * $b->height; if ($areaA < $areaB) { return -1; } elseif ($areaA > $areaB) { return 1; } else { return 0; } } print_r(array_udiff($array1, $array2, 'compare_by_area')); ?> The above example will output: Array ( [0] => stdClass Object ( [width] => 11 [height] => 3 ) [1] => stdClass Object ( [width] => 7 [height] => 1 ) ) Example #2 array_udiff(3) example using DateTime Objects <?php class MyCalendar { public $free = array(); public $booked = array(); public function __construct($week = 'now') { $start = new DateTime($week); $start->modify('Monday this week midnight'); $end = clone $start; $end->modify('Friday this week midnight'); $interval = new DateInterval('P1D'); foreach (new DatePeriod($start, $interval, $end) as $freeTime) { $this->free[] = $freeTime; } } public function bookAppointment(DateTime $date, $note) { $this->booked[] = array('date' => $date->modify('midnight'), 'note' => $note); } public function checkAvailability() { return array_udiff($this->free, $this->booked, array($this, 'customCompare')); } public function customCompare($free, $booked) { if (is_array($free)) $a = $free['date']; else $a = $free; if (is_array($booked)) $b = $booked['date']; else $b = $booked; if ($a == $b) { return 0; } elseif ($a > $b) { return 1; } else { return -1; } } } // Create a calendar for weekly appointments $myCalendar = new MyCalendar; // Book some appointments for this week $myCalendar->bookAppointment(new DateTime('Monday this week'), "Cleaning GoogleGuy's apartment."); $myCalendar->bookAppointment(new DateTime('Wednesday this week'), "Going on a snowboarding trip."); $myCalendar->bookAppointment(new DateTime('Friday this week'), "Fixing buggy code."); // Check availability of days by comparing $booked dates against $free dates echo "I'm available on the following days this week... "; foreach ($myCalendar->checkAvailability() as $free) { echo $free->format('l'), " "; } echo " "; echo "I'm busy on the following days this week... "; foreach ($myCalendar->booked as $booked) { echo $booked['date']->format('l'), ": ", $booked['note'], " "; } ?> The above example will output: I'm available on the following days this week... Tuesday Thursday I'm busy on the following days this week... Monday: Cleaning GoogleGuy's apartment. Wednesday: Going on a snowboarding trip. Friday: Fixing buggy code. NOTES
Note Please note that this function only checks one dimension of a n-dimensional array. Of course you can check deeper dimensions by using array_udiff($array1[0], $array2[0], "data_compare_func");. SEE ALSO
array_diff(3), array_diff_assoc(3), array_diff_uassoc(3), array_udiff_assoc(3), array_udiff_uassoc(3), array_intersect(3), array_inter- sect_assoc(3), array_uintersect(3), array_uintersect_assoc(3), array_uintersect_uassoc(3). PHP Documentation Group ARRAY_UDIFF(3)
All times are GMT -4. The time now is 05:45 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy