新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
怎么在Linux中利用shell獲去字符串所在行數(shù)及位置-創(chuàng)新互聯(lián)
怎么在Linux中利用shell 獲去字符串所在行數(shù)及位置?針對這個問題,這篇文章詳細介紹了相對應(yīng)的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。
01 獲取字符串所在的行數(shù)
方式一:用grep -n
[root@root]# cat test apple bit create delect exe flow good [root@root]# cat test | grep -n exe 5:exe [root@root]# cat test | grep -n exe | awk -F ":" '{print $1}' 5
方式二:用sed -n '/查詢的字符串/=' 文件
[root@root]# cat test apple bit create delect exe flow good [root@root]# [root@root]# sed -n '/exe/=' test 5
02 獲取字符串中字符所在的位置
方式一:用awk -F 和 wc -c 組合
[root@root]# echo 'uellevcmpottcap' | awk -F 'ott' '{print $1}'; uellevcmp [root@root]# echo 'uellevcmpottcap' | awk -F 'ott' '{print $1}' | wc -c 10
方式二:用awk 'BEGIN{print index("'${str}'","'${str1}'") }'
[root@root]# str='uellevcmpottcap';str1='ott';awk 'BEGIN{print index("'${str}'","'${str1}'") }' 10
什么是Linux系統(tǒng)
Linux是一種免費使用和自由傳播的類UNIX操作系統(tǒng),是一個基于POSIX的多用戶、多任務(wù)、支持多線程和多CPU的操作系統(tǒng),使用Linux能運行主要的Unix工具軟件、應(yīng)用程序和網(wǎng)絡(luò)協(xié)議。
關(guān)于怎么在Linux中利用shell 獲去字符串所在行數(shù)及位置問題的解答就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關(guān)知識。
網(wǎng)頁題目:怎么在Linux中利用shell獲去字符串所在行數(shù)及位置-創(chuàng)新互聯(lián)
文章分享:http://fisionsoft.com.cn/article/cecoeg.html