Bash脚本到mkdir的文件的每一行已由定界符拆分? [英] Bash script to mkdir on each line of a file that has been split by a delimiter?

查看:69
本文介绍了Bash脚本到mkdir的文件的每一行已由定界符拆分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图弄清楚如何逐行遍历.txt文件(filemappings.txt),然后使用tab(\t)作为分隔符分割每一行,以便我们可以在选项卡(mkdir -p)的右侧.

Trying to figure out how to iterate through a .txt file (filemappings.txt) line by line, then split each line using tab(\t) as a delimiter so that we can create the directory specified on the right of the tab (mkdir -p).

读取filemappings.txt,然后按tab

Reading filemappings.txt and then splitting each line by tab

server/ /client/app/
server/a/   /client/app/a/
server/b/   /client/app/b/

会变成

mkdir -p /client/app/
mkdir -p /client/app/a/
mkdir -p /client/app/b/

xargs是一个不错的选择吗?为什么或为什么不呢?

Would xargs be a good option? Why or why not?

推荐答案

cut -f 2 filemappings.txt | tr '\n' '\0' | xargs -0 mkdir -p 

xargs -0非常适合矢量运算.

xargs -0 is great for vector operations.

这篇关于Bash脚本到mkdir的文件的每一行已由定界符拆分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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