[SOLVED] Append output of a command in column wise manner
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hello!
Suppose a command generates output in every 1 hr. in form:
Code:
Server1
1
2
3
4
5
And I am redirecting this output in some file, let's say output.txt
So I want that everytime this script runs, it appends the output in next column of the file output.txt, not below the existing content. It should look like:
Apparently it can be managed using paste cmd, but I do not want to generate too many files.
What's "too many"? Using paste would require just one temp file per run. To avoid any temp files, I guess you could read the current file entirely into memory:
"<<<word" is a here string, a simplified form of the here document.
IIRC, at least some of your work is being done on a Unix box, without the availability of GNU tools, and perhaps an older version of bash? Remember to always detail the environment you're using in your posts if it's significantly different from that of a recent Linux distro.
But if the tools that you use can't handle the syntax given, then you'll have to find some workaround. I don't see any problem with using text files if that's all you have available. You just need three files, used in rotation.
It's not working properly or may be I couldn't implement it correctly.
What does "not working properly" mean? Please post error messages, or the actual outcome. My guess is you have an older version of bash, or a plain bourne shell.
Quote:
Sample.sh script:
Code:
echo "usre1 user2" > output.txt
...
This script is overwriting output.txt every time. I was assuming a script that writes to stdout.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.