When I run:cat filename | cut -f3 | head -1I get the following result:appleHowever when I save this to a file by using:cat filename | cut -f3 | head -1 > newfileI then open this using php with the following:$variable = file_get_contents(newfile); echo $variable; // PRINTS appleBut when I do the following the output is 6!!!echo strlen($variable); // PRINTS 6 WHEN I EXPECT 5!$variable = apple;echo $variable; // NOW PRINTS 5Any idea how to avoid this? I need to use this variable in a lookup function and it wont match my lookup due to the extra character which I cannot identify. When I echo the following:$variable = file_get_contents(newfile); echo TEST1;echo TEST2;echo $variable;echo TEST3;echo TEST4;I get the following output:TEST1TEST2appleTEST3TEST4So it must be printing a new line somehow....?!?
cat filename | cut -f2 | head -1 > newfile contains more characters than expected
command line;files;php;cut;head
Indeed, that's your \n, that is counted by strlenIn PHP, you have rtrim (http://php.net/manual/fr/function.rtrim.php) to remove all \n, \t, \r, \0 & \x0B from the right end of your string.