用cut或awk

时间:2017-11-01 15:15:15

标签: grep cut

我试图削减一行星号输出。 完整的一行:

[2017-11-01 08:23:58] NOTICE[13443]: res_pjsip/pjsip_distributor.c:659 log_failed_request: Request 'INVITE' from '"66666" <sip:66666@192.168.1.248>' failed for '163.172.107.10:5070' (callid: f64a37f3cc5a88f4cd957ecb7b65a14f) - No matching endpoint found

我需要在输出中只看到这个163.172.107.10 所以我的命令是:

cat test | grep endpoint | awk '{print $13}' | awk -F':' '{print $1}'

我的输出:

'163.172.107.10

但我无法摆脱&#39; (撇号) 我试过了:cut -d&#39;&#39;&#39;&#39; 但那并没有奏效 有什么建议吗?

3 个答案:

答案 0 :(得分:1)

如果此行遵循上述类似的模式,那么

试试这个

gawk -F"'" '{print $6}' | cut -d":" -f1

,如

echo "[2017-11-01 08:23:58] NOTICE[13443]: res_pjsip/pjsip_distributor.c:659 log_failed_request: Request 'INVITE' from '"66666" <sip:66666@192.168.1.248>' failed for '163.172.107.10:5070' (callid: f64a37f3cc5a88f4cd957ecb7b65a14f) - No matching endpoint found" | gawk -F"'" '{print $6}' | cut -d":" -f1

答案 1 :(得分:0)

如果以下内容有帮助,请与我们联系。

cat test | grep endpoint | awk '{print $13}' | awk -F':' '{print $1}' | tr -d "'"

答案 2 :(得分:0)

如果您的Input_file与显示的示例相同,那么以下内容可能对您有帮助。

<?php
ob_start();
require_once 'Classes/PHPExcel.php';
require_once 'Classes/PHPExcel/IOFactory.php';
$name = $_GET['user_name'];
$mail = $_GET['user_email'];
$msg = $_GET['user_message'];
$to = 'theemailid'; 
$email_subject = "Excel Sheet:  $name";
$email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $mail\n\nMessage:$msg";
$headers = "From:theemailid\n";
$headers .= "Reply-To: $mail";
mail($to,$email_subject,$email_body,$headers);
$objPHPExcel = PHPExcel_IOFactory::load("excel.xlsx");
$objPHPExcel->setActiveSheetIndex(0);
$row = $objPHPExcel->getActiveSheet()->getHighestRow()+1;
date_default_timezone_set('Asia/Calcutta');
$date = date('Y-m-d h:i:s A');
$objPHPExcel->getActiveSheet()->SetCellValue('A'.$row, $date);
objPHPExcel->getActiveSheet()->SetCellValue('B'.$row,$_GET['user_name']);
$objPHPExcel->getActiveSheet()->SetCellValue('C'.$row, $_GET['user_email']);
$objPHPExcel->getActiveSheet()->SetCellValue('D'.$row, $_GET['user_message']);
$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
$objWriter->save("excel.xlsx");
?>