LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-24-2017, 06:02 AM   #1
amalendu.rakshit
LQ Newbie
 
Registered: Jun 2010
Posts: 11

Rep: Reputation: 0
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.
 
Old 07-24-2017, 07:38 AM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
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"?
 
Old 07-24-2017, 09:12 AM   #3
linustalman
LQ Guru
 
Registered: Mar 2010
Location: Ireland
Distribution: Debian 12 Bookworm
Posts: 5,717

Rep: Reputation: 479Reputation: 479Reputation: 479Reputation: 479Reputation: 479
Greetings AR.

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

Edit: Thread was since moved from Member Intro section.

Last edited by linustalman; 07-24-2017 at 01:52 PM.
 
Old 07-24-2017, 01:44 PM   #4
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,264
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
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.
 
Old 07-24-2017, 02:10 PM   #5
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,881

Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660
Quote:
Originally Posted by amalendu.rakshit View Post
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

.
 
1 members found this post helpful.
Old 07-25-2017, 06:01 AM   #6
amalendu.rakshit
LQ Newbie
 
Registered: Jun 2010
Posts: 11

Original Poster
Rep: Reputation: 0
Thumbs up

It's working! Thanx Martin!
 
Old 07-26-2017, 12:00 AM   #7
amalendu.rakshit
LQ Newbie
 
Registered: Jun 2010
Posts: 11

Original Poster
Rep: Reputation: 0
Thumbs up

Thank You all for such quick response!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
difference between the contents of the two files literaturedevourer Programming 2 10-29-2014 03:09 AM
Mail only files with contents kais1 Linux - Newbie 1 06-29-2011 02:55 AM
Editing contents of 8 files at once mmahulo Linux - Newbie 7 12-22-2008 04:07 AM
text files contents jaepi Programming 5 06-18-2008 10:07 AM
Comparing files contents? hhegab Linux - Newbie 3 07-01-2004 12:45 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration