【问题标题】:Adding contents of Files添加文件的内容
【发布时间】:2021-02-04 16:02:03
【问题描述】:

我是 shell/Linux 的新手,我想知道是否可以使用 CAT 或 AWK 将两个文件附加在一起,而无需将它们放在下面的文本,这是:

text1
text2

我们来看看file1和file2,都是.txt。

file1.txt

I hold some info
I have other info
I like code

file2.txt

that is sensible
that isn't sensible
& I like coffee 

现在,我想知道的是是否可以将 file2.txt 附加到 file1.txt 并使其变成这样的:

I hold some info that is sensible
I have other info that isn't sensible
I like code & I like coffee

我当前的代码是:

    #!/bin/bash
cat /etc/passwd | grep ^a | tail -n +3 | head | cut -d':' -f1,5  | cut -c 2- | sed 's/:/;/g; s/,/;/g' | sed 's/$/a/g' > aux.txt
cat aux.txt | grep -Eo '[0-9]{1,9}' | sed 's/$/@iscte-iul.pt;100/g' > aux1.txt
cat aux.txt aux1.txt | cut -f1-7 > aux.txt
cat aux.txt > pacientes.txt
rm aux.txt | rm  aux1.txt

【问题讨论】:

标签: linux bash shell


【解决方案1】:

使用paste:

$ paste -d ' ' file1.txt file2.txt
I hold some info that is sensible
I have other info that isn't sensible
I like code & I like coffee

【讨论】:

  • 哇,我是怎么找贴的,忘了原来的贴了……非常感谢哈哈
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-29
  • 1970-01-01
  • 1970-01-01
  • 2019-08-20
  • 1970-01-01
  • 2023-03-21
相关资源
最近更新 更多