AWK - 如何删除与字段分隔第一列 [英] awk - how to delete first column with field separator

查看:977
本文介绍了AWK - 如何删除与字段分隔第一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有psented如下数据$ P $ CSV文件

I have a csv file with data presented as follows

87540221|1356438283301|1356438284971|1356438292151697
87540258|1356438283301|1356438284971|1356438292151697
87549647|1356438283301|1356438284971|1356438292151697

我试图挽救的第一列到一个新文件(没有字段分隔符,然后与第一场分离沿着删除主CSV文件中的第一列。

I'm trying to save the first column to a new file (without field separator , and then delete the first column from the main csv file along with the first field separator.

任何想法?

这是我曾尝试迄今

awk 'BEGIN{FS=OFS="|"}{$1="";sub("|,"")}1'

,但它不工作

推荐答案

这是简单的用剪切

$ cut -d'|' -f1 infile
87540221
87540258
87549647

$ cut -d'|' -f2- infile
1356438283301|1356438284971|1356438292151697
1356438283301|1356438284971|1356438292151697
1356438283301|1356438284971|1356438292151697

只是重定向到你想要的文件:

Just redirect into the file you want:

$ cut -d'|' -f1 infile > outfile1

$ cut -d'|' -f2- infile > outfile2 && mv outfile2 file 

这篇关于AWK - 如何删除与字段分隔第一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆