Hi,
I have an urgent task here. I am required to sort a flat file based on multiple columns which are based on the character position in that line. I am restricted to use the character position instead of the space and sort +1 +2 etc to do the sorting.
I understand that there is a previous... (8 Replies)
I have 20000 numbers present in a file in each line like
25663,
65465,
74579,
56446,
..
..
I have created a table in db with single number column in it.
create table testhari (no number(9));
I want to insert all these numbers into that table. how can i do it?
can anybody please... (4 Replies)
Hi,
As part of migrating a script from SunOS to MP RAS, the following script is not functioning in desired way.
sort -t\| -u +6 -7 +12 -14 textfile1.out > \
textfile2uniq.out
The -u is fetching unique records differently on SunOS and MP RAS Pentium IV. And thus the records... (1 Reply)
Hi gurus, hoping someone can help with a sed line that can do the following...
I have a flat file with about 1000 records, but in order to import into openoffice spreadsheet, I need to create a delimited file. I'd like to do 2 things with the SED command:
1- add a pipe character "|" at the end... (4 Replies)
I have a fixed length file that need to be sorted according to the following rule
IF B=1 ORDER by A,B
Else ORDER by A,C
Input file is
ABC
131
112
122
231
212
222
Output needed
ABC
112
131
122
212
231
222 (1 Reply)
hi,
Please suggest me how to do this logic
say i am dynamically taking a file name into the script.
when ever a file name it should sort the all the records based on the first character in every line except the heading line and ending line.
for example
file1
heading... (1 Reply)
I have a flat file that contains records similar to the following two lines;
1984/11/08 7 700000 123456789 2
1984/11/08 1941/05/19 7 700000 123456789 2
The 123456789 2 represents an account number, this is how I identify the duplicate record.
The ### signs represent... (4 Replies)
Hi Everyone,
I have below record set. File is fixed widht file
101newjersyus 20150110
101nboston us 20150103
102boston us 20140106
102boston us 20140103
I need to group record based on first 3 letters in our case(101 and 102)
and sort last 8 digit in ascending order and print only... (4 Replies)
I have a texinfo file containing book records and I want to sort them. An example is shown below.
Records are separated by two blank lines. The sort pattern I want to sort is starting from the beginning of the year declaration and finishing at the beginning of the book title where I use the... (4 Replies)
Discussion started by: Danette
4 Replies
LEARN ABOUT PHP
scandir
SCANDIR(3) 1 SCANDIR(3)scandir - List files and directories inside the specified pathSYNOPSIS
array scandir (string $directory, [int $sorting_order = SCANDIR_SORT_ASCENDING], [resource $context])
DESCRIPTION
Returns an array of files and directories from the $directory.
PARAMETERS
o $directory
- The directory that will be scanned.
o $sorting_order
- By default, the sorted order is alphabetical in ascending order. If the optional $sorting_order is set to SCANDIR_SORT_DESCEND-
ING, then the sort order is alphabetical in descending order. If it is set to SCANDIR_SORT_NONE then the result is unsorted.
o $context
- For a description of the $context parameter, refer to the streams section of the manual.
RETURN VALUES
Returns an array of filenames on success, or FALSE on failure. If $directory is not a directory, then boolean FALSE is returned, and an
error of level E_WARNING is generated.
CHANGELOG
+--------+---------------------------------------------------+
|Version | |
| | |
| | Description |
| | |
+--------+---------------------------------------------------+
| 5.4.0 | |
| | |
| | $sorting_orderconstants were added. Any nonzero |
| | value caused descending order in previous ver- |
| | sions. So for all PHP versions, use 0 for ascend- |
| | ing order, and 1 for descending order. An option |
| | for SCANDIR_SORT_NONE behavior did not exist |
| | prior to PHP 5.4.0. |
| | |
+--------+---------------------------------------------------+
EXAMPLES
Example #1
A simple scandir(3) example
<?php
$dir = '/tmp';
$files1 = scandir($dir);
$files2 = scandir($dir, 1);
print_r($files1);
print_r($files2);
?>
The above example will output something similar to:
Array
(
[0] => .
[1] => ..
[2] => bar.php
[3] => foo.txt
[4] => somedir
)
Array
(
[0] => somedir
[1] => foo.txt
[2] => bar.php
[3] => ..
[4] => .
)
Example #2
PHP 4 alternatives to scandir(3)
<?php
$dir = "/tmp";
$dh = opendir($dir);
while (false !== ($filename = readdir($dh))) {
$files[] = $filename;
}
sort($files);
print_r($files);
rsort($files);
print_r($files);
?>
The above example will output something similar to:
Array
(
[0] => .
[1] => ..
[2] => bar.php
[3] => foo.txt
[4] => somedir
)
Array
(
[0] => somedir
[1] => foo.txt
[2] => bar.php
[3] => ..
[4] => .
)
NOTES
Tip
A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen(3) for more details on how to
specify the filename. See the "Supported Protocols and Wrappers" for links to information about what abilities the various wrappers
have, notes on their usage, and information on any predefined variables they may provide.
SEE ALSO opendir(3), readdir(3), glob(3), is_dir(3), sort(3).
PHP Documentation Group SCANDIR(3)