08-13-2002
Hey Peter,
With a small modification here my code also works...
But I have very important doubts to be cleared.....
Here is the code...
{
max=11;
line=substr($0,0,max) ;
firstcol=substr(line,0,3) ;
secondcol=substr(line,5,3);
thirdcol=substr(line,9,1)
if ( firstcol != field1 || secondcol != field2 )
{ print firstcol "," secondcol "," thirdcol; field1=firstcol; field2=secondcol }
}
And I executed it as
awk -f cmp_rec test.dat > log
Ofcourse, i can execute it as u said too....
First let me clarify with you whether my understanding is right...
it is col to col comparison right??
for example,
aaa|bbb|1
aaa|bbb|2 would give me aaa|bbb|1
xxx|yyy|3 xxx|yyy|3
xxx|yyy|4 zzz|rrr|5
zzz|rrr|5
Bcos it compares aaa and bbb of the first row and the aaa and bbb of the second row...
if the first col and the second col of the first row is not equal to the first and second col of the second row, then that first instance is printed..
Now coming to the doubt,
In the above code why shoud i assign
field1=firstcol; field2=secondcol
Are these field1 and field2 key fields???? meaning system defined..???
Can you explain???
Thanks,
Nisha
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
I need to copy my Live Db Instance to my Test Db Instance
Can somebody please tell me the easiest way to go about this
It is an Informix Database running on HP-UX
Thanks (0 Replies)
Discussion started by: cobdeng
0 Replies
2. Linux
hi frnds
here i m trying to configure OTRS instance but i m getting the following error message
while runnning through browser.
I m writing the following http://192.168.1.55:8080/otrs2/index.pl
"
#!/usr/bin/perl -w... (7 Replies)
Discussion started by: naik_mit
7 Replies
3. Shell Programming and Scripting
Hi,
I have a script. I want only one instance of the script to be running at any point of the time. How can I do it.
what would be the exact format of the ps command for doing this. For example the name of my script is "Inst.sh"
Thanx in advance (2 Replies)
Discussion started by: sendhil
2 Replies
4. Shell Programming and Scripting
Hi,
I have a challenging task,in which i have to find the duplicate files by its name and size,then i need to take anyone of the file.Then i need to open the file and find for more than one pattern and count of that pattern.
Note:These are the samples of two files,but i can have more... (2 Replies)
Discussion started by: jerome Sukumar
2 Replies
5. Shell Programming and Scripting
Alright, I think I know what I am doing with sed(which probably means I don't). But I cant figure out how to replace just the first occurance of a string. I have tried sed, ed, and grep but can't seem to figure it out. If you have any suggestions I am open to anything! (3 Replies)
Discussion started by: IronHorse7
3 Replies
6. Shell Programming and Scripting
Hi All,
I have a property in a file as:
property=value=a
If I use FS="=" then I want only first = to be considered as field separator and remaining as value
echo -e "property=value=a" | awk -F= '{print $2}'
ie my $2 should be value=a
Can anyone please help me with this. I need it in... (3 Replies)
Discussion started by: gurukottur
3 Replies
7. Shell Programming and Scripting
Guys please see below functions to return a status depending on user input. Both seem to work the same.
The second way has a : line which i can't understand or see in a ksh manual anywhere. Instead of doing the variable change if its empty on this line the first function simply does it on the... (7 Replies)
Discussion started by: lavascript
7 Replies
8. Red Hat
Hi ,
Maximum How many instances of apache can we run in
one box? (2 Replies)
Discussion started by: krish4linux
2 Replies
9. Shell Programming and Scripting
Hi All,
I have a input file like
1| abc
1| abcd
1| abcde
2| abc
2| abcd
3| abcde
I want the output like
1| abcde
2| abcde
Any help would be highly appreciated.
Thanks in advance. (9 Replies)
Discussion started by: lrkp
9 Replies
10. UNIX for Advanced & Expert Users
Hi,
I want to get the only application name from the server.
Ex:
if i give $ ps -ef | grep bw.
It will show all BW process with entire path. It will little confuse to list out the process. Can anyone have syntax to get only the instance name. I need this for be, hawk,ems also.
Please... (2 Replies)
Discussion started by: ckchelladurai
2 Replies
FPUTCSV(3) 1 FPUTCSV(3)
fputcsv - Format line as CSV and write to file pointer
SYNOPSIS
int fputcsv (resource $handle, array $fields, [string $delimiter = ","], [string $enclosure = '"'], [string $escape_char = "
DESCRIPTION
fputcsv(3) formats a line (passed as a $fields array) as CSV and write it (terminated by a newline) to the specified file $handle.
PARAMETERS
o $handle
-The file pointer must be valid, and must point to a file successfully opened by fopen(3) or fsockopen(3) (and not yet closed by
fclose(3)).
o $fields
- An array of values.
o $delimiter
- The optional $delimiter parameter sets the field delimiter (one character only).
o $enclosure
- The optional $enclosure parameter sets the field enclosure (one character only).
o $escape_char
- The optional $escape_char parameter sets the escape character (one character only).
RETURN VALUES
Returns the length of the written string or FALSE on failure.
CHANGELOG
+--------+---------------------------------------+
|Version | |
| | |
| | Description |
| | |
+--------+---------------------------------------+
| 5.5.4 | |
| | |
| | The $escape_char parameter was added |
| | |
+--------+---------------------------------------+
EXAMPLES
Example #1
fputcsv(3) example
<?php
$list = array (
array('aaa', 'bbb', 'ccc', 'dddd'),
array('123', '456', '789'),
array('"aaa"', '"bbb"')
);
$fp = fopen('file.csv', 'w');
foreach ($list as $fields) {
fputcsv($fp, $fields);
}
fclose($fp);
?>
The above example will write the following to file.csv:
aaa,bbb,ccc,dddd
123,456,789
"""aaa""","""bbb"""
NOTES
Note
If PHP is not properly recognizing the line endings when reading files either on or created by a Macintosh computer, enabling the
auto_detect_line_endings run-time configuration option may help resolve the problem.
SEE ALSO
fgetcsv(3).
PHP Documentation Group FPUTCSV(3)