Take input from one file and add to other file in particular column

We have two files

159 149 

and

2e49.pem,Apr 29 07:07:13 2017 GMT,275 2f69.pem,Apr 29 07:18:21 2017 GMT,275 

I want to replace the last word, 275, in the second file with the corresponding line from the first file.

It should look like this:

2e49.pem,Apr 29 07:07:13 2017 GMT,159 2f69.pem,Apr 29 07:18:21 2017 GMT,149 

Replay

sed 's/[^,]*$//' file2 | paste -d '\0' - file1

Or with awk:

awk -F , -v OFS=, '{getline $NF < "file1"; print}' file2

To remove the bit after the last comma in the second file (including the comma):

$ sed 's/,[0-9]*$//' second.txt
2e49.pem,Apr 29 07:07:13 2017 GMT
2f69.pem,Apr 29 07:18:21 2017 GMT

Pasting the first file onto the end of each line of that output, with a comma in between:

$ 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

This is assuming that your shell understands process substitution with <( ... ) (bash and ksh93 does).

Note: This is very similar to St├ęphane's sed solution, but I'm also deleting the comma to avoid the \0 delimiter to paste, and I'm using process substitution.

Category: text processing Time: 2016-07-28 Views: 0

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.189 (s). 12 q(s)