sed 's/[^,]*$//' file2 | paste -d 'awk -F , -v OFS=, '{getline $NF < "file1"; print}' file2
' - file1
Ou com awk :
sed 's/[^,]*$//' file2 | paste -d 'awk -F , -v OFS=, '{getline $NF < "file1"; print}' file2
' - file1
Temos dois arquivos
159
149
e
2e49.pem,Apr 29 07:07:13 2017 GMT,275
2f69.pem,Apr 29 07:18:21 2017 GMT,275
Eu quero substituir a última palavra, 275 , no segundo arquivo pela linha correspondente do primeiro arquivo.
Deveria ser assim:
2e49.pem,Apr 29 07:07:13 2017 GMT,159
2f69.pem,Apr 29 07:18:21 2017 GMT,149
sed 's/[^,]*$//' file2 | paste -d 'awk -F , -v OFS=, '{getline $NF < "file1"; print}' file2
' - file1
Ou com awk :
sed 's/[^,]*$//' file2 | paste -d 'awk -F , -v OFS=, '{getline $NF < "file1"; print}' file2
' - file1
Para remover o bit após a última vírgula no segundo arquivo (incluindo a vírgula):
$ sed 's/,[0-9]*$//' second.txt
2e49.pem,Apr 29 07:07:13 2017 GMT
2f69.pem,Apr 29 07:18:21 2017 GMT
Colando o primeiro arquivo no final de cada linha da saída, com uma vírgula entre:
$ paste -d ',' <( sed 's/,[0-9]*$//' second.txt ) first.txt
2e49.pem,Apr 29 07:07:13 2017 GMT,159
2f69.pem,Apr 29 07:18:21 2017 GMT,149
Isto supõe que o seu shell entenda a substituição do processo por <( ... ) ( bash e ksh93 ).
Nota: Isso é muito semelhante à solução sed de Stéphane, mas também estou excluindo a vírgula para evitar o delimitador para %code% e estou usando a substituição de processo. paste
Tags text-processing