LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Map the contents of three files! (https://www.linuxquestions.org/questions/programming-9/map-the-contents-of-three-files-4175610485/)

amalendu.rakshit 07-24-2017 06:02 AM

Map the contents of three files!
 
Hi,
I wants to map the contents of three files and send them into one consolidated file.
I have the following 3 files;

# cat server
abc01.example.com
abc02.example.com
abc03.example.com
abc04.example.com
abc05.example.com
abc06.example.com
abc07.example.com


# cat status
ACTIVE
ACTIVE
ACTIVE
ACTIVE
ACTIVE
ACTIVE
ACTIVE
ACTIVE


# cat buildDate
2017-02-16T14:51:28Z
2017-05-22T08:10:01Z
2017-06-01T12:40:28Z
2017-05-09T12:47:04Z
2017-05-09T10:21:22Z
2017-05-08T09:26:06Z
2017-04-24T11:08:03Z

I wants to achieve something similar as follows,


abc01.example.com#ACTIVE#2017-02-16T14:51:28Z
abc02.example.com#ACTIVE#2017-05-22T08:10:01Z
abc03.example.com#ACTIVE#2017-06-01T12:40:28Z
abc04.example.com#ACTIVE#2017-05-09T12:47:04Z
abc05.example.com#ACTIVE#2017-05-09T10:21:22Z
abc06.example.com#ACTIVE#2017-05-08T09:26:06Z
abc07.example.com#ACTIVE#2017-04-24T11:08:03Z

I try with the following loop, but not working;

for i in `cat server`
do
for j in `cat status`
do
for k in `cat buildDate`
do
cat $i $j $k > /tmp/output
done
done
done

Could you please help to achieve the goal!

Regards.

rtmistler 07-24-2017 07:38 AM

Hi. Recommend you use [code][/code] tags around your code.

Instead of using cat to output these variables to the temp output file, have you tried to use "echo"?

linustalman 07-24-2017 09:12 AM

Greetings AR.

* Please note that this section is only for intros. *

Edit: Thread was since moved from Member Intro section.

astrogeek 07-24-2017 01:44 PM

Welcome to LQ!

To get better exposure your post has been moved to the Programming forum where it is more appropriate.

As already suggested, please place your code snippets inside [CODE]...[/CODE] tags for better readability. You may type those yourself or click the "#" button in the edit controls.

Finally, also as suggested by rtmistler, your loop code is nearly sufficient, but in the output line you should use echo or printf instead of cat, along with some formatting to get the desired result. With echo you will need to insert the # separators shown in your example, or with printf put them in the format string.

danielbmartin 07-24-2017 02:10 PM

Quote:

Originally Posted by amalendu.rakshit (Post 5739192)
Could you please help to achieve the goal!

This paste ...
Code:

paste -d# $Server $Status $Build >$OutFile
... produced this OutFile ...
Code:

abc01.example.com#ACTIVE#2017-02-16T14:51:28Z
abc02.example.com#ACTIVE#2017-05-22T08:10:01Z
abc03.example.com#ACTIVE#2017-06-01T12:40:28Z
abc04.example.com#ACTIVE#2017-05-09T12:47:04Z
abc05.example.com#ACTIVE#2017-05-09T10:21:22Z
abc06.example.com#ACTIVE#2017-05-08T09:26:06Z
abc07.example.com#ACTIVE#2017-04-24T11:08:03Z

Daniel B. Martin

.

amalendu.rakshit 07-25-2017 06:01 AM

It's working! Thanx Martin!

amalendu.rakshit 07-26-2017 12:00 AM

Thank You all for such quick response!


All times are GMT -5. The time now is 03:56 AM.