在Bash中的CSV文件中拆分列 [英] Splitting a column in a csv file in Bash

查看:123
本文介绍了在Bash中的CSV文件中拆分列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从csv文件的第二列中提取值,并将提取的值存储在新列中.

I would like to extract values from the second column in my csv file and store the extracted values in a new column.

我的数据集样本:

page_name      post_id                        page_id
A              86680728811_272953252761568    86680728811   
A              86680728811_273859942672742    86680728811
B              86680728033_281125741936891    86680728033
B              86680728033_10150500662053812  86680728033

我想提取下划线后的数字并将其存储在新列中.样本输出:

I would like to extract the number that come after the underscore and store them in a new column. Sample output:

page_name      post_id                        page_id
A              272953252761568                86680728811   
A              273859942672742                86680728811
B              281125741936891                86680728033
B              10150500662053812              86680728033

我尝试使用此代码:

cat FB_Dataset.csv | sed -Ee 's/(.*)post_id/\1post_id/' -e 's/,[_ ]/,/' -e 's/_/,/'

但是我没有得到想要的输出.

but I don't get the desired output.

感谢您的帮助.谢谢.

推荐答案

sed 's/[0-9][0-9]*_//' < a.csv  

其中a.csv是包含原始数据的文件
编辑以添加[0-9]

where a.csv is the file with your original data
edited to add [0-9]

这篇关于在Bash中的CSV文件中拆分列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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