Context:
I am using sed in a cronjob to change the dates in a separate sql script every week. Each week the dates must be updated to reflect the Monday and Friday of the previous week. I have solved the problem but in solving it I discovered a major weakness in my knowledge of sed.
Lines to be changed ( SQL excerpt ): My current solution: My question ( 2 parts ):
1. How would you simplify this or improve this?
2. Regarding Fridays: How would you express the following in sed?:
Find all lines starting with "datediff" AND NOT ending with "and"
THEN
Replace the 2nd date string with the variable for last friday.
Here's what I've tried ~
Keeps saying "Event not found".
Thanks!
Bub
UPDATE: I figured out one possible solution. Maybe not the most elegant ...thoughts? ~
Note for noobs: Those are side-by-side single quotes NOT double quotes in the example above.
Please Help... I am trying to manipulte the following line
Before :
<user:Account_Password>002786</user:Account_Password>
the password is the "variable", i need to delete / omit the password in the file, (it occurs several thousand times)
so the tag line looks like
After:... (4 Replies)
hi,
I have a problem about the Oracle related components. I'm not able to find any answer yet, and waiting for your responses...
Here is the configuration of my system:
* an IBM P550 machine,
* an AIX 5.3 running on it and
* an oracle database, already installed on it.
The problem (or... (1 Reply)
I guess it was getting a little messy on the other post so here goes:
Link to previous post for Question:
https://www.unix.com/shell-programming-scripting/111338-awk-replace-particular-field.html
Continuation of Question
hey i was messing around a bit ... made me wonder...
If the... (1 Reply)
Hi Guys,
Req your help in searching and replacing the word that comes after equals(=) symbol
I would like to replace the sting in bold with a string in variable.
d=ABCDF8C44C22
# grep -i NIM_MASTERID ${_NIMINFO}
export NIM_MASTERID=00CDF8C44C00
I'm looking to replace any word that... (4 Replies)
Hi,
I have line in input file as below:
3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL
My expected output for line in the file must be :
"1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL"
Can someone... (7 Replies)
logs:
"/home/abc/public_html/index.php"
"/home/abc/public_html/index.php"
"/home/xyz/public_html/index.php"
"/home/xyz/public_html/index.php"
"/home/xyz/public_html/index.php"
how to use "cut" or "awk" or "sed" to get the following result:
abc
abc
xyz
xyz
xyz (8 Replies)
Hi, everyone.
I need to write a program to get io info based on libperfstat.
But the "write time" of a disk is just half of the value get from iostat.
I'm confused and can't explain. Help please.
How I calculate "write service time per sec":
In iostat:
write service... (0 Replies)
I am trying to use the below sed command to replace all "|" to ^, in a folder had 50 dat files. when i tried with 1 file it worked but when i tried with wild card, is not working.
sed -i 's/"|"/\^/g' *.dat
Is this the proper way to use sed command thank you very much for help. (3 Replies)
I need to find two matches in the output from ps. I am searching with ps -ef |grep mysql for:
my.cnf
/bin/sh /usr/bin/mysqld_safe --defaults-file=/data/mysql/master/agis_core/etc/my.cnf
after this match I want to search back and match the hostname which is x number of lines back, above the... (2 Replies)
Discussion started by: bash_in_my_head
2 Replies
LEARN ABOUT PHP
array_udiff
ARRAY_UDIFF(3) 1 ARRAY_UDIFF(3)array_udiff - Computes the difference of arrays by using a callback function for data comparisonSYNOPSIS
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)