I have a dynamic variable names html print multiple inputs , what I do is this:
for( $t=0 ; $t < 2; $t++){
$varservice[$t]='servicio'.$indexbook[$t];
}
for($j=0 ; $j < 2; $j++){
$servicio[$j]=$request->get($varservice[$j]);
}
in the end, the service variable [ $ j ] , print null, it does not recognize the IndexBook variable that brings the name the html input and bring this information ... so that I can do? I print that variable comp .... I'm a driver
Related
I want to generate more data based on some sample data i already have in a file stored in Unix location.
looking for a unix shell code.
ID,FN,LN,Gender
1,John,hopkins,M
2,Andrew,Singh,M
3,Ram,Lakshman,M
4,ABC,DEF,F
5,Virendra,Sehwag,F
6,Sachin,Tendulkar,F
You could use awk to read the existing data into an array and then keep printing it over and over with new IDs:
awk -F, -v OFS=, -v n=100 '
BEGIN {
l = 0;
}
/^[0-9]/ {
a[l] = $2","$3","$4;
l++;
}
{ print }
END {
for ( i = l; i <= n; i++ ) {
printf "%d,%s\n", i, a[i%l];
}
}
'
n is the number of IDs you want (existing IDs + generated).
I have a file let's say files_190911.csv whose contents are as follows.
EDR_MPU023_09_20190911080534.csv.gz
EDR_MPU023_10_20190911081301.csv.gz
EDR_MPU023_11_20190911083544.csv.gz
EDR_MPU023_14_20190911091405.csv.gz
EDR_MPU023_15_20190911105513.csv.gz
EDR_MPU023_16_20190911105911.csv.gz
EDR_MPU024_50_20190911235332.csv.gz
EDR_MPU024_51_20190911235400.csv.gz
EDR_MPU024_52_20190911235501.csv.gz
EDR_MPU024_54_20190911235805.csv.gz
EDR_MPU024_55_20190911235937.csv.gz
EDR_MPU025_24_20190911000050.csv.gz
EDR_MPU025_25_20190911000155.csv.gz
EDR_MPU025_26_20190911000302.csv.gz
EDR_MPU025_29_20190911000624.csv.gz
I want to make a list of missing sequence from those using bash script.
Every MPUXXX has its own sequence. So there are multiple series of sequences in that file.
The datetime for missing list will use from previous sequence.
From the sample above, the result will be like this.
EDR_MPU023_12_20190911083544.csv.gz
EDR_MPU023_13_20190911083544.csv.gz
EDR_MPU024_53_20190911235501.csv.gz
EDR_MPU025_27_20190911000302.csv.gz
EDR_MPU025_28_20190911000302.csv.gz
It would be simpler if there were only a single sequence.
So I can use something like this.
awk '{for(i=p+1; i<$1; i++) print i} {p=$1}'
But I know this can't be used for multiple sequence.
EDITED (Thanks #Cyrus!)
AWK is your friend:
#!/usr/bin/awk
BEGIN {
FS="[^0-9]*"
last_seq = 0;
next_serial = 0;
}
{
cur_seq = $2;
cur_serial = $3;
if (cur_seq != last_seq) {
last_seq = cur_seq;
ts = $4
prev = cur_serial;
} else {
if (cur_serial == next_serial) {
ts = $4;
} else {
for (i = next_serial; i < cur_serial; i++) {
print "EDR_MPU" last_seq "_" i "_" ts ".csv.gz"
}
}
}
next_serial = cur_serial + 1;
}
And then you do:
$ < files_190911.csv awk -f script.awk
EDR_MPU023_12_20190911083544.csv.gz
EDR_MPU023_13_20190911083544.csv.gz
EDR_MPU024_53_20190911235501.csv.gz
EDR_MPU025_27_20190911000302.csv.gz
EDR_MPU025_28_20190911000302.csv.gz
The assignment to FS= splits lines by the regex. The rest program detects holes in sequences and prints them with the appropriate timestamp.
I have a massive text file that I need to convert to an CSV file so I can import it to an MySQL database.
The text file looks like this:
Original text file
VL;1;1001;Productname 1;Description 1;2;MTR;METER;217883;10000;20180402;1;010206;&10;PRODUCER1;;N;10000;;
VA;2;4044773815245;V;
VA;3;0036453;V;
VL;1;1002;Productname 2;This is product decrtiption for 2 product;2;MTR;METER;140365;10000;20180402;1;010206;&10;PRODUCER1;;N;10000;;
VX;WEIGHT;7500
VX;VOLUME;3249
VX;DIMENSJON;57x57x1000
VA;2;4044773452884;V;
VA;3;0036479;V;
VL;1;1003;Productname 3;Description......;2;MTR;METER;1575;10000;20171006;1;010606;&10;PRODUCER1;;N;10000;;
VX;PDF;1003.pdf
VX;IMAGE;1003.png
VX;BASEINFO;http://127.0.0.1/1003/
VX;WEIGHT;20
VX;DIMENSJON;0x7x0
VX;UNSPSC;26121616
VA;2;7070613017149;V;
VA;3;1000116;V;
Wanted result
I will need to convert it into a CSV file that looks like this:
type; Productnumber; Productname; Description; measurement_unit; price_unit; price_unit_txt; price; crowd; price_date; status; block_number; discount_group; manufac; type; stocked; sales_package; discount; price_type; PDF; IMAGE; baseinfo; WEIGHT; VOLUME; dimensjon; UNSPSC; va_2; va_3;
1; 1001; Productname 1; Description 1; 2; MTR; METER; 217883; 10000; 20180402 1; 010206; &10; PRODUCER1; ; N; 10000; ; ; ; ; ; ; ; ; ; 4044773815245; 0036453;
1; 1002; Productname 2; Description 2; 2; MTR; METER; 140365; 10000; 20180402; 1; 010206; &10; PRODUCER2 ; N; 10000; ; ; ; ; ; 7500; 3249; 57x57x1000; ; 4044773452884; 0036479;
1; 1003; Productname 3; Description ABC 3; 2; MTR; METER; 1575; 10000; 20171006; 1; 010606; &10; PRODUCER3; ; N; 10000; ; ; 1003.pdf; 1003.png; http://127.0.0.1/1003/; 20; ; 0x7x0; 26121616; 7070613017149; 1000116;
Explanation of the original file
The fist product line is always starting with VL and then continue in this order:
type;Productnumber;Productname;Description;measurement_unit;price_unit;price_unit_txt;price;crowd;price_date;status;block_number;discount_group;manufac;type;stocked;sales_package;discount;price_type;
PDF is always on a new line starting with VX;PDF;
IMAGE is always on a new line starting with VX;IMAGE;
baseinfo is always on a new line starting with VX;BASEINFO;
WEIGHT is always on a new line starting with VX;WEIGHT;
VOLUME is always on a new line starting with VX;VOLUME;
dimensjon is always on a new line starting with VX;DIMENSJON;
UNSPSC is always on a new line starting with VX;UNSPSC;
va_2 is always on a new line starting with VA;2;
va_3 is always on a new line starting with VA;3;
Hope someone can help me out with this :)
a way possible (not the wole solution)
#!/bin/bash
awk -F';' '
function init() {
# formation line to print_line
line = vl pdf image baseinfo weight volume dimensjon unspsc va_2 va_3
# erase ^M (\r)
gsub( /\r/;"";line )
# print a block
print line
# initialisation variables
vl = pdf = image = baseinfo = weight = volume = dimensjon = unspsc = va_2 = va_3 = ";"
}
# head/title, note that "%12s" format with 12 characters width
BEGIN { printf ( "%12s; %s; %s; %s; %s; %s; %s; %s; %s; %s;","vl","pdf","image","baseinfo ","weight","volume","dimensjon","unspsc","va_2","va_3" ) }
/^VL/ { init(); ; vl = sprintf( "%12s; %s; %s; %s; ", $3, $4, $5, $6 ) }
/^VX;WEIGHT;/ { weight = sprintf( "%s; ", $3 )}
# .. another conditions
END { init() }
' file.dat # > outputfile.csv
for test:
cat << end > file.dat
VL;1;1001;Productname 1;Description 1;2;MTR;METER;217883;10000;20180402;1;010206;&10;PRODUCER1;;N;10000;;
VA;2;4044773815245;V;
VA;3;0036453;V;
VL;1;1002;Productname 2;This is product decrtiption for 2 product;2;MTR;METER;140365;10000;20180402;1;010206;&10;PRODUCER1;;N;10000;;
VX;WEIGHT;7500
VX;VOLUME;3249
VX;DIMENSJON;57x57x1000
VA;2;4044773452884;V;
VA;3;0036479;V;
VL;1;1003;Productname 3;Description......;2;MTR;METER;1575;10000;20171006;1;010606;&10;PRODUCER1;;N;10000;;
VX;PDF;1003.pdf
VX;IMAGE;1003.png
VX;BASEINFO;http://127.0.0.1/1003/
VX;WEIGHT;20
VX;DIMENSJON;0x7x0
VX;UNSPSC;26121616
VA;2;7070613017149;V;
VA;3;1000116;V;
end
ouput
vl; pdf; image; baseinfo ; weight; volume; dimensjon; unspsc; va_2; va_3;
1001; Productname 1; Description 1; 2; ;;;;;;;;;
1002; Productname 2; This is product decrtiption for 2 product; 2; ;;;7500; ;;;;;
1003; Productname 3; Description......; 2; ;;;20; ;;;;;
I am trying to pass the values for xlim and ylim into my octave script as command line arguments. What I curently have is:
arg_list = argv ();
filename = arg_list{1};
minVal = arg_list{2};
maxVal = arg_list{3};
if (minVal >= maxVal)
disp(["min (" minVal ") must be less than max (" maxVal ")"]);
else
%prepare plot
plot(x,y);
xlim([minVal maxVal]);
ylim([minVal maxVal]);
endif
I call the script form a linux terminal like this:
for f in ./AllValues/Acceleration*.csv; do
echo "Processing file: $f";
if echo "$f" | egrep -q "High" ; then
./calc.m $f 0 50;
else
./calc.m $f 0 20;
fi
done
When the min value is 0, the xlim and ylim commands are ignored and the auto-values are used. When I try to set another value, eg. ./script.m file.csv 7 20, the test fails and I get the output min (7) must be less than max (20).
I tried to cast the arguments to int32:
minVal = int32(arg_list{2});
maxVal = int32(arg_list{3});
but that generates an error when trying to set the xlim and ylim, even with a 0 value for min.
I also tried to surround the arguments in single or double quotes:
./script.m file.csv '7' '20'
./script.m file.csv "7" "20"
but that did not change anything.
Any ideas what's wrong with my script?
Wrap the assignments with str2double:
minVal = str2double (arg_list{2});
maxVal = str2double (arg_list{3});
There isn't type cast between string and numerical types, that is why your attempt with int32 have failed.
I have a strange problem with Magentos EAV-Databasesystem.I want to store a dataset like the next codeblock. But one value 'StoreId' was not stored. Do you have any Idea why one of eight values can stored in a table.
public function populateEntriesAction()
{
//return;
for ( $i = 0; $i < 5; $i++ )
{
$branchEntry = Mage::getModel('branch/eavisbranch');
$branchEntry->setName('abc ' . $i);
$branchEntry->setStreet('abcdefg ' . $i);
.....
$branchEntry->setStorePickup(false);
$branchEntry->setStoreId('3');
$branchEntry->save();
}
echo 'Done';
}