Bash - Shell Script - Simple script to create and write variables to txt file.

Posted on 2008-10-02
Last Modified: 2013-12-26
Can someone help me with a simple bash script to create a file 'test.txt' and write variables to it.
and then write it to the txt file with a : delimited format. It will always be just one line. It would be like this:
The last thing it has to do is place carriage returns on the end of each line so its in windows txt format.

I guess this could be done with sed, but not sure how. Thanks for any help.
Question by:WinPE
LVL 84

Accepted Solution

ozo earned 250 total points
ID: 22627473
echo $Variable1:$Variable2:$Variable3:$Variable4 > test.txt

LVL 48

Assisted Solution

Tintin earned 250 total points
ID: 22638497
To have windows end of line characters, you need to do

echo -e "$Variable1:$Variable2:$Variable3:$Variable4\r" >test.txt

You may or may not need the -e flag depending on your Unix flavour.

Author Closing Comment

ID: 31502514
Thanks Guys!

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now