开发者社区> 问答> 正文

awk 分割字符串,但是我只要以第一个符号分割:报错

例如:

某文件中存在下列sql语句

sql1=select name,age frome peop_info where 1=1

我想读取文件,然后用awk取得后面的sql值

 $awk -F "=" '{print $2}' 这样遇到有多个等号的就只取第一个等号后面,第二个等号前面的

如何只根据第一个等号分割?



 

展开
收起
kun坤 2020-06-06 23:51:52 1455 0
1 条回答
写回答
取消 提交回答
  • 用awk也行的

    ~$ echo "sql1=select name,age frome peop_info where 1=1" | awk -F'=' '{s="";for(i=2;i<=NF;i++)s=s""(i==NF?$i:$i"=");print s}'

    select name,age frome peop_info where 1=1
    ######
    localhost:~ macbook$ echo "sql1=select name,age frome peop_info where 1=1" | cut -d '=' -f 2-
    select name,age frome peop_info where 1=1
    localhost:~ macbook$
    选用合适的工具
    ######

    t="sql1=select name,age frome peop_info where 1=1"

    echo ${t/sql1=/}

    2020-06-06 23:51:57
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载