Hi All,
My Input file looks like below:
Input:
100,200,300
$fw=`head -1 test.csv | awk -F, '{print \$1}'`;
$fw="'$fw"
$fw="$fw'"
print $fw
Output:'100'
I want the first field to be printed in single quotes ('') like above.
I could get the ouptput but the problem is single quote (') is printed in next line below.
'100
'
I dont know how to avoid this space.
era
September 24, 2008, 6:52am
2
To remove a trailing newline in Perl, use chomp
why use awk/head when you can do all in Perl??
era
September 24, 2008, 7:01am
4
Why use either when you can do it all in shell?
IFS=, read first others <file.csv
echo "'$first'"
I want to capture first field in a file and check for some conditions. File has got 10 million records.
perl -e '@a=split(/ +/, <>);print $a[0]' file
era
September 24, 2008, 2:57pm
7
You want to split on comma /,/ not whitespace.
The number of lines doesn't really matter if you only read the first line. All of the proposed solutions I believe have this property.