linux如何切换英文标点符号,如何在linux中用sed从一个单词的结尾和单词的开头删除标点符号?(How to remove punctuation from end and start of a...

I am trying to figure out how many times each word occurs in a file using linux.

I have placed each word from my file onto a new line by using the code below.

sed -i 's/ /\n/g' books2

I am now trying to replace the start and end of the word with a blank as some words contain punctuation. I am currently doing this by using the following code, but it does not seem to be working. Once I have this I will be able to run a command that will count all the words and return a list of counts on all the words. Can someone correct me on how to remove the punctuation?

sed -i 's/\([^[:alpha:]]\)$//' books2 #this is my attempt to remove the punctuality at the end of the word

sed -i 's/\([^[:alpha:]]\)^.*//' books2 #this is my attempt to remove the punctuality from the front.

When I run either of the lines of code above my file becomes empty. Why is this?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值