If anyone can shed some light on my issue that'd be great. Please don't down-vote me; I'm new to the language and the OS itself and I'm trying my best to research before asking questions, so any positivity is appreciated.
Below is an extract from a script that I've written in PHP, but contains a system command that executes in bash. Now, the reason for this is because it allows me to use the awk function which is ideal in the scenario I've been presented with. I'm trying to get the fourth or fifth element of a string (stored in $line), which I then plan to work with. However whenever I execute it with the code below I am presented with the following error:
PHP Parse error: syntax error, unexpected T_LNUMBER, expecting T_VARIABLE or '$' in /home/hugh/HughScripts/ParseOutputForFieldsV2.php on line 16
Line 16 is my first system command:
system("echo \"$line\" | awk '{$1=$2=$3=$4=""; print $0}'");
However I'm unsure due to my lack of expertise with both PHP and the system function, what exactly is causing my issue. Can anyone possibly shed some light on it? I've tried researching the problem, however the error is quite generic and my situation is quite unique, as a lot of the 'awk' problems on the web are part of scenario where the person is executing it from the CLI rather than a PHP script.
Here's an example of what data would be in the $line variable:
Gi1/1 down down Neustar : NX/IB49912 : 1Mbps - Offshore SLA
Code below:
$skipFirstLine = 1;
foreach($outputFile as &$line)
{
if($skipFirstLine == 0)
{
if(strpos($line, 'admin down'))
{
//$fieldamount=system("echo \"$line\" | awk '{ print NF}'");
//echo $fieldamount;
system("echo \"$line\" | awk '{$1=$2=$3=$4=""; print $0}'");
}
else
{
system("echo \"$line\" | awk '{$1=$2=$3=""; print $0}'");
}
}
else
{
$skipFirstLine = 0;
}
}