我有一个文件中有一堆文字,用换行符隔开:在命令行上执行多级文本操作?
ex。
"This is sentence 1.\n"
"This is sentence 2.\n"
"This is sentence 3. It has more characters then some other ones.\n"
"This is sentence 4. Again it also has a whole bunch of characters.\n"
我希望能够使用一些组命令行工具,这将对于每个行,计算每行的字符数,然后,如果有超过每该行X个字符,按句点分割(“。”),然后计算分割线每个元素中的字符数。
ex。最终的输出,通过行号:
1. 24
2. 24
3. 69: 20, 49 (i.e. "This is sentence 3" has 20 characters, "It has more characters then some other ones" has 49 characters)
wc
只需要输入一个文件名,所以我无法指挥它,它采取的文本字符串做字符数
head -n2 processed.txt | tr "." "\n" | xargs -0 -I line wc -m line
给我的错误: “:开:没有这样的文件或目录”
欢迎来到SO!标签*命令行*有点过于笼统。你应该指定你正在使用的shell,因为答案会因shell而异。在这种情况下,它似乎是bash或sh + POSIX utils。 –
* wc只将输入文件名称作为输入* - 实际上它可以从stdin开始工作。试试'echo hello | wc -c' – damienfrancois
有点晚了,但感谢您的建议! –