When double quoting $line, the * chars will be preserved, and your awk scripts will work. Did you consider reading the variables immediately with bash ?
EDIT: Can't you, BTW, make ORACLE use other delimiters?
How can i set a variable field delimiter using awk??
I wanna do something like this ,but i canīt get the correct syntaxis :
VARI=TEST
echo "0121212TESTxvcshaashd"|awk 'FS="$VARI" {print $2}'
Thanks. (2 Replies)
Hello,
I had posted earlier about printing fields using AWK, but now I have a slightly different problem. I have text files in the format:
1*2,3,4,5
and wish to print the first, third, and fifth fields, including the asterisk and commas. In other words, after filtering it should look... (1 Reply)
Hello,
I need an awk script to receive a variable that's an decimal value such as 009 or 031 and then convert this value to an ascii character to use as the FS (field separator for the input file).
For example,
009 should be converted to an ascii tab
031 should be converted to an ascii... (1 Reply)
Dear All,
1.txt (tab in between each value in a line)
a b c
a b c
a c d
you can see below, why with ~ i can output with tab, but = cannot?
# awk -F'\t' '$2 ~ /b/' 1
a b c
a b c
# awk -F'\t' '$2 = "b"' 1
a b c
a b c
a b d
... (1 Reply)
Hi All,
I wanted to find 200th field value in delimiter file using awk.?
awk '{print $200}' inputfile
I am getting error message :-
awk: The field 200 must be in the range 0 to 199.
The source line number is 1.
The error context is
{print >>> $200 <<< }
using... (4 Replies)
Hello, I am using awk to match text in a tab separated field and am able to do so when matching the exact word. My problem is that I would like to match any sequence of text in the tab-separated field without having to match it all. Any help will be appreciated. Please see the code below.
awk... (3 Replies)
hi,
just wanted to make a shortcut of this one
a="a b c"
b=`echo $a | awk '{print $2}'`
echo "the middle is $b"
why can't i do this:
a="a b c"
echo "the middle is ${`echo $a | awk '{print $2}'`}" <- bad substitution :wall:
thanks (6 Replies)
Hi Experts,
i need to change delimiter from tab to ","
sample test file
cat test
A0000368 A29938511 072569352 5 Any 2 for Ģ1.00 BUTCHERS|CAT FOOD|400G Sep 12 2012 12:00AM Jan 5 2014 11:59PM Sep 7 2012 12:00AM M 2.000 group 5
... (2 Replies)
We have a csv file as mentioned below and the requirement is to change the date format in file as mentioned below.
Current file (file.csv)
----------------------
empname,date_of_join,dept,date_of_resignation
ram,08/09/2015,sales,21/06/2016
"akash,sahu",08/10/2015,IT,21/07/2016
... (6 Replies)
I will start with an example of what I'm trying to do and then describe how I am approaching the issue.
File
PS028,005
Lexeme HRS # M #
PhraseType 1(1:1) 7(7)
PhraseLab 501 503
ClauseType ZYq0
PS028,005
Lexeme W # L> # BNH # M #... (17 Replies)
Discussion started by: jvoot
17 Replies
LEARN ABOUT PHP
fgetcsv
FGETCSV(3) 1 FGETCSV(3)fgetcsv - Gets line from file pointer and parse for CSV fieldsSYNOPSIS
array fgetcsv (resource $handle, [int $length], [string $delimiter = ","], [string $enclosure = '"'], [string $escape = "
DESCRIPTION
Similar to fgets(3) except that fgetcsv(3) parses the line it reads for fields in CSV format and returns an array containing the fields
read.
PARAMETERS
o $handle
- A valid file pointer to a file successfully opened by fopen(3), popen(3), or fsockopen(3).
o $length
- Must be greater than the longest line (in characters) to be found in the CSV file (allowing for trailing line-end characters).
It became optional in PHP 5. Omitting this parameter (or setting it to 0 in PHP 5.1.0 and later) the maximum line length is not
limited, which is slightly slower.
o $delimiter
- The optional $delimiter parameter sets the field delimiter (one character only).
o $enclosure
- The optional $enclosure parameter sets the field enclosure character (one character only).
o $escape
- The optional $escape parameter sets the escape character (one character only).
RETURN VALUES
Returns an indexed array containing the fields read.
Note
A blank line in a CSV file will be returned as an array comprising a single null field, and will not be treated as an error.
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.
fgetcsv(3) returns NULL if an invalid $handle is supplied or FALSE on other errors, including end of file.
CHANGELOG
+--------+---------------------------------------------------+
|Version | |
| | |
| | Description |
| | |
+--------+---------------------------------------------------+
| 5.3.0 | |
| | |
| | The $escape parameter was added |
| | |
| 5.1.0 | |
| | |
| | The $length is now optional. Default is 0, mean- |
| | ing no length limit. |
| | |
| 4.3.5 | |
| | |
| | fgetcsv(3) is now binary safe |
| | |
+--------+---------------------------------------------------+
EXAMPLES
Example #1
Read and print the entire contents of a CSV file
<?php
$row = 1;
if (($handle = fopen("test.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
echo "<p> $num fields in line $row: <br /></p>
";
$row++;
for ($c=0; $c < $num; $c++) {
echo $data[$c] . "<br />
";
}
}
fclose($handle);
}
?>
NOTES
Note
Locale setting is taken into account by this function. If $LANG is e.g. en_US.UTF-8, files in one-byte encoding are read wrong by
this function.
SEE ALSO str_getcsv(3), explode(3), file(3), pack(3), fputcsv(3).
PHP Documentation Group FGETCSV(3)