i would suggest to first read in the whole file in three array, one for the serial, one for the user and one for the ipadd.
Code:
declare -a SERIAL ACCT IPADD
let count=0
while IFS=, read a b c
do
SERIAL[$count]=$a; ACCT[$count]=$b; IPADD[$count]=$c; ((count++))
done < file
This sets the internal field separator to "," and reads the three comma separate fields into the three variables which are pushed into the declared arrays.
Now you can search this array like this:
Code:
let i=0
while [[ $i -lt ${#SERIAL[@]} ]]
do
[[ ${SERIAL[${i}]} = W120* ]] && printf "%s %s\n" ${ACCT[${i}]} ${IPADD[${i}]}
((i++))
done
This loops trough the array. ${#SERIAL[@]} gives you the number of entries of an array. If a certain SERIAL is found, the corresponding data are output.
Hi,
Please help me out on this
I have to store some distribution lists(dl) in a file say mail.txt
Say the file format be
d1 = alok@yahoo.co.in;alvin@rediffmail.com;vijay@yahoo.com; & so on...
d2 = abhinav@gmail.com;dalpit@hotmail.com;garima@yahoo.com;& so on...
d3 = ....
& so on
Now what... (1 Reply)
How do I search for a string within a file and return the names of the file that contain the string? I would like to search directories and sub-directories. (4 Replies)
I need to be able to search multiple fields within a file that contain blank (nothing).
Not sure what command to use? thought it would be grep but not sure how to write it
The reason is i have a script that when it does this and identifies a field which has a blank it errors out of the script... (4 Replies)
Hey Everyone!
I have searched around for this on Unix.com and Google, and I'm either not phrasing my search properly or this is not as simple as I thought...
I have a script that runs on a nightly basis that pulls one field worth of data from an internal MySQL database and populates to an... (2 Replies)
I am on AIX Unix. I want to read a flat file for a string in a certain byte. I want to find the value: 943034 in column 56; and write out just those records to another file. Also, could I get the line/record number of where it was found in the input file?
Thank you,
sboxtops (1 Reply)
Hi
I want to search for a specific pattern in file
Say
ABC;HELLO_UNIX_WORLD;PQR
ABC;HELLO_UNIX_WORLD_IS_NOT_ENOUGH;XYZ
ABC;HELLO_UNIX_FORUM;LMN
Pattern to search is : "HELLO_UNIX_*****" and not "HELLO_UNIX_***_***_"
I mean after "HELLO_UNIX" there can only be one word.In this case... (2 Replies)
Hi All,
Can you please guide me to search a string in a particular column of file and return the line number of the line where it was found using awk. As an example :
abc.txt
7000,john,2,1,0,1,6
7001,elen,2,2,0,1,7
7002,sami,2,3,0,1,6
7003,mike,1,4,0,2,1
8001,nike,1,5,0,1,8... (3 Replies)
Hi
I am new to unix and newbie to this forum. I need help in writing a gawk script that search and replace particular text in a flat file.
Input file text :
ZIDE_CONTROL000 100000000003869920900000300000001ISYNC 000002225489 0000000002232122 20120321 16:40:53
ZIDE_RECORD000... (5 Replies)
I would like to know awk command to delete the specific feild from a flat file delimited by '|' if the first feild starts with 354
I tried
awk 'BEGIN {FS=OFS="|"} {$16=""; sub(/\|/, "")}'1
Input file:
354|||||GROUND||97||JUDD STREET|||LONDON||WC1H 9JG|ADI001|
354|||||FLAT 1... (10 Replies)
Sample txt file :
OK00001111112|
OK00003443434|skjdaskldj
OK32812983918|asidisoado
OK00000000001|
ZM02910291029|sldkjaslkjdasldjk
what would be the shell script to figure out the blank space (if any) after the pipe sign? (4 Replies)
Discussion started by: chatwithsaurav
4 Replies
LEARN ABOUT PHP
maxdb_insert_id
MAXDB_INSERT_ID(3) 1 MAXDB_INSERT_ID(3)maxdb_insert_id - Returns the auto generated id used in the last query
Procedural style
SYNOPSIS
mixed maxdb_insert_id (resource $link)
DESCRIPTION
Object oriented style
mixed$maxdb->insert_id ()
The maxdb_insert_id(3) function returns the ID generated by a query on a table with a column having the DEFAULT SERIAL attribute. If the
last query wasn't an INSERT or UPDATE statement or if the modified table does not have a column with the DEFAULT SERIAL attribute, this
function will return zero.
RETURN VALUES
The value of the DEFAULT SERIAL field that was updated by the previous query. Returns zero if there was no previous query on the connec-
tion or if the query did not update an DEFAULT_SERIAL value.
Note
If the number is greater than maximal int value, maxdb_insert_id(3) will return a string.
EXAMPLES
Example #1
Object oriented style
<?php
$maxdb = new maxdb("localhost", "MONA", "RED", "DEMODB");
/* check connection */
if (maxdb_connect_errno()) {
printf("Connect failed: %s
", maxdb_connect_error());
exit();
}
maxdb_report (MAXDB_REPORT_OFF);
$maxdb->query("DROP TABLE mycity");
maxdb_report (MAXDB_REPORT_ERROR);
$maxdb->query("CREATE TABLE mycity LIKE hotel.city");
$maxdb->query("ALTER TABLE mycity ADD id FIXED(11) DEFAULT SERIAL");
$query = "INSERT INTO mycity (zip,name,state) VALUES ('12203','Albany' ,'NY')";
$maxdb->query($query);
printf ("New Record has id %d.
", $maxdb->insert_id);
/* drop table */
$maxdb->query("DROP TABLE mycity");
/* close connection */
$maxdb->close();
?>
Example #2
Procedural style
<?php
$link = maxdb_connect("localhost", "MONA", "RED", "DEMODB");
/* check connection */
if (maxdb_connect_errno()) {
printf("Connect failed: %s
", maxdb_connect_error());
exit();
}
maxdb_report (MAXDB_REPORT_OFF);
maxdb_query($link,"DROP TABLE mycity");
maxdb_report (MAXDB_REPORT_ERROR);
maxdb_query($link, "CREATE TABLE mycity LIKE hotel.city");
maxdb_query($link, "ALTER TABLE mycity ADD id FIXED(11) DEFAULT SERIAL");
$query = "INSERT INTO mycity (zip,name,state) VALUES ('12203','Albany' ,'NY')";
maxdb_query($link, $query);
printf ("New Record has id %d.
", maxdb_insert_id($link));
/* drop table */
maxdb_query($link, "DROP TABLE mycity");
/* close connection */
maxdb_close($link);
?>
The above example will output something similar to:
New Record has id 1.
PHP Documentation Group MAXDB_INSERT_ID(3)