String 换行
我有一个文件,上面有很多这样的行 代码: 我想移除所有东西直到“|” 如何使用sed/awk实现这一点String 换行,string,replace,sed,awk,String,Replace,Sed,Awk,我有一个文件,上面有很多这样的行 代码: 我想移除所有东西直到“|” 如何使用sed/awk实现这一点 蒂亚 确保画线的起点和终点: sed -e 's/^.*\(|.*\)$/\1/' 在awk中,您可以将字段分隔符设置为任何值 awk 'BEGIN{ FS="|" }{print FS, $2}' yourfilename 试试这个 awk '{print $3}' file 试试这个 sed 's/^[^|]*.//' 基本上从行的开头开始,用空格替换行中从开始到“|”的所有内
蒂亚 确保画线的起点和终点:
sed -e 's/^.*\(|.*\)$/\1/'
在awk中,您可以将字段分隔符设置为任何值
awk 'BEGIN{ FS="|" }{print FS, $2}' yourfilename
试试这个
awk '{print $3}' file
试试这个
sed 's/^[^|]*.//'
基本上从行的开头开始,用空格替换行中从开始到“|”的所有内容:
astr | bstr | cstr | dstr
贪婪的匹配
sed 's/.*|//' < file # will result: ` dstr`
sed 's/.*|/|/' < file # will result: `| dstr`
sed 's/^[^|]*|//' < file # will result: ` bstr | cstr | dstr`
sed 's/^[^|]*|/|/' < file # will result: `| bstr | cstr | dstr`
他不想听到第三个字,再检查一下这个问题。他想要这个:
awk-F'|'{print$2}'文件
@ssapkota。我的解决方案与您的相同,只是我使用默认的FS。当然,这是根据他的样本数据,并假设它们在……上是一致的,本质相同:awk-F'|'{print$2}'文件名
sed 's/^[^|]*|//' < file # will result: ` bstr | cstr | dstr`
sed 's/^[^|]*|/|/' < file # will result: `| bstr | cstr | dstr`
cut -d'|' -f-1 < file # will result: `astr `
cut -d'|' -f-2 < file # will result: `astr | bstr `
cut -d'|' -f2- < file # will result: ` bstr | cstr | dstr`
cut -d'|' -f3- < file # will result: ` cstr | dstr`
cut -d'|' -f2 < file # will result: ` bstr `
cut -d'|' -f2-3 < file # will result: ` bstr | cstr`
cut -d'|' -f2,4 < file # will result: ` bstr | dstr`