简体   繁体   English

如何通过带有特殊字符分隔符的awk读取行和列

[英]How to read rows and columns via awk with special character separator

Can this be done more easily in a single command? 可以通过一个命令更轻松地完成此操作吗?

Read line 10 and column 2 from the file where the separator is ^ 从分隔符为^的文件中读取第10行和第2列

cat file | awk 'FNR==10 {print}' | awk -v  FS=^ '{print $2}' 

如果^是所有记录的主/公用字段分隔符-只需应用以下awk表达式就足够了:

awk -F'^' 'NR==10{ print $2; exit }' file

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM