10-14-2016
You're welcome,
-a means read into an array (when using
bash).
F is the name of the array
printf is the preferred and standardized alternative to
echo. The first field to
printf is the "format string" . "%s" means "string" and "\n" means new line". See:
printf or the bash man page.
To get all the element of the array one normally uses:
"${F[@]}"
"${F[@]# }" does the same, but in addition it uses
parameter expansion and
# means cut off a leading space if it exists.
Since
F is an array it will work on every element of the array (more about this in the bash man page).
With the while read loop, for every line of the input file, the array
F gets filled anew.
Last edited by Scrutinizer; 10-14-2016 at 05:34 AM..
This User Gave Thanks to Scrutinizer For This Post:
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
How can i read all the unique words in a file, i used -
cat comment_file.txt | /usr/xpg6/bin/tr -sc 'A-Za-z' '/012'
and
cat comment_file.txt | /usr/xpg6/bin/tr -sdc 'A-Za-z' '/012'
but they didnt worked..... (5 Replies)
Discussion started by: aditya.ece1985
5 Replies
2. Shell Programming and Scripting
hi,
I am a begginer in unix and i want to know how to open a file and read it and separate the numbers & words and storing it in separate files, Using shell scripting.
Please help me out for this.
Regards
S.Kamakshi (2 Replies)
Discussion started by: kamakshi s
2 Replies
3. Shell Programming and Scripting
Hi....can you guys help me out in this script??
Below is a portion text file and it contains these:
GEF001 000093625 MKL002510 000001 000000 000000 000000 000000 000000 000001
GEF001 000093625 MKL003604 000001 000000 000000 000000 000000 000000 000001
GEF001 000093625 MKL005675 000001... (1 Reply)
Discussion started by: pallavishetty
1 Replies
4. Shell Programming and Scripting
hi all,
I have this file with some user data.
example:
$cat myfile.txt
FName|LName|Gender|Company|Branch|Bday|Salary|Age
aaaa|bbbb|male|cccc|dddd|19900814|15000|20|
eeee|asdg|male|gggg|ksgu|19911216|||
aara|bdbm|male|kkkk|acke|19931018||23|
asad|kfjg|male|kkkc|gkgg|19921213|14000|24|... (4 Replies)
Discussion started by: srimal
4 Replies
5. Shell Programming and Scripting
I am having one text file and i need to read that data from my shell script.
I will expain you the scenario:
Script look like:
For name type 1:
For age type 2:
For Salary type3:
echo "Enter the input:"
read the data
if input is 1 then go to the Text file and print the... (2 Replies)
Discussion started by: dineshmurs
2 Replies
6. Shell Programming and Scripting
Hello,
I have a file ( say file1) which has lines like below.
xxxx:xxxx,yyyy,1234,efgh
zzzz:zzzz,kkkk,pppp,1234,xxxx,uuuu,oooo
dddd:dddd
here the word before ":" ( ie: xxxx) is the file name and the string after : are also file names, but each file name separated by ","
In case of... (20 Replies)
Discussion started by: pradeepmacha
20 Replies
7. Shell Programming and Scripting
hi
i am trying to extract some specific data out of a text file using regular expressions with shell script
that is using a multiline grep .. and the tool i am using is pcregrep so that i can get compatibility with perl's regular expressions
for a sample data like this, i am trying to grab... (6 Replies)
Discussion started by: vemkiran
6 Replies
8. Shell Programming and Scripting
Hello programmers,
I need to create a list of unique words from a text file using PERL...may i have the code for that please?
Thank you (1 Reply)
Discussion started by: alsohari
1 Replies
9. UNIX for Dummies Questions & Answers
sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies
10. Shell Programming and Scripting
I have input data looks like this which is a part of a csv file
7,1265,76548,"0102:04"
8,1266,76545,"0112:04"
I need to make the output data should look like this and the output data will be part of text file:
7|1265000 |7654899 |A|
8|12660000 |76545999 |B|
The logic behind the... (6 Replies)
Discussion started by: RJG
6 Replies
LEARN ABOUT PHP
parse_url
PARSE_URL(3) 1 PARSE_URL(3)
parse_url - Parse a URL and return its components
SYNOPSIS
mixed parse_url (string $url, [int $component = -1])
DESCRIPTION
This function parses a URL and returns an associative array containing any of the various components of the URL that are present.
This function is not meant to validate the given URL, it only breaks it up into the above listed parts. Partial URLs are also accepted,
parse_url(3) tries its best to parse them correctly.
PARAMETERS
o $url
- The URL to parse. Invalid characters are replaced by _.
o $component
- Specify one of PHP_URL_SCHEME, PHP_URL_HOST, PHP_URL_PORT, PHP_URL_USER, PHP_URL_PASS, PHP_URL_PATH, PHP_URL_QUERY or
PHP_URL_FRAGMENT to retrieve just a specific URL component as a string (except when PHP_URL_PORT is given, in which case the
return value will be an integer).
RETURN VALUES
On seriously malformed URLs, parse_url(3) may return FALSE.
If the $component parameter is omitted, an associative array is returned. At least one element will be present within the array. Potential
keys within this array are:
o$scheme - e.g. http
o$host
o$port
o$user
o$pass
o$path
o$query - after the question mark
?
o$fragment - after the hashmark
#
If the $component parameter is specified, parse_url(3) returns a string (or an integer, in the case of PHP_URL_PORT) instead of an array.
If the requested component doesn't exist within the given URL, NULL will be returned.
CHANGELOG
+--------+---------------------------------------------------+
|Version | |
| | |
| | Description |
| | |
+--------+---------------------------------------------------+
| 5.4.7 | |
| | |
| | Fixed host recognition when scheme is omitted |
| | and a leading component separator is present. |
| | |
| 5.3.3 | |
| | |
| | Removed the E_WARNING that was emitted when URL |
| | parsing failed. |
| | |
| 5.1.2 | |
| | |
| | Added the $component parameter. |
| | |
+--------+---------------------------------------------------+
EXAMPLES
Example #1
A parse_url(3) example
<?php
$url = 'http://username:password@hostname:9090/path?arg=value#anchor';
var_dump(parse_url($url));
var_dump(parse_url($url, PHP_URL_SCHEME));
var_dump(parse_url($url, PHP_URL_USER));
var_dump(parse_url($url, PHP_URL_PASS));
var_dump(parse_url($url, PHP_URL_HOST));
var_dump(parse_url($url, PHP_URL_PORT));
var_dump(parse_url($url, PHP_URL_PATH));
var_dump(parse_url($url, PHP_URL_QUERY));
var_dump(parse_url($url, PHP_URL_FRAGMENT));
?>
The above example will output:
array(8) {
["scheme"]=>
string(4) "http"
["host"]=>
string(8) "hostname"
["port"]=>
int(9090)
["user"]=>
string(8) "username"
["pass"]=>
string(8) "password"
["path"]=>
string(5) "/path"
["query"]=>
string(9) "arg=value"
["fragment"]=>
string(6) "anchor"
}
string(4) "http"
string(8) "username"
string(8) "password"
string(8) "hostname"
int(9090)
string(5) "/path"
string(9) "arg=value"
string(6) "anchor"
Example #2
A parse_url(3) example with missing scheme
<?php
$url = '//www.example.com/path?googleguy=googley';
// Prior to 5.4.7 this would show the path as "//www.example.com/path"
var_dump(parse_url($url));
?>
The above example will output:
array(3) {
["host"]=>
string(15) "www.example.com"
["path"]=>
string(5) "/path"
["query"]=>
string(17) "googleguy=googley"
}
NOTES
Note
This function doesn't work with relative URLs.
Note
This function is intended specifically for the purpose of parsing URLs and not URIs. However, to comply with PHP's backwards com-
patibility requirements it makes an exception for the file:// scheme where triple slashes (file:///...) are allowed. For any other
scheme this is invalid.
SEE ALSO
pathinfo(3), parse_str(3), http_build_query(3), http_build_url(3), dirname(3), basename(3), RFC 3986.
PHP Documentation Group PARSE_URL(3)