Solved

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

Posted on 2008-10-02
3
1,262 Views
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.
Variable1=10.2.4.1
Variable2=10.2.4.2
Variable3=10.2.4.3
Variable4=10.2.4.4
and then write it to the txt file with a : delimited format. It will always be just one line. It would be like this:
10.2.4.1:10.2.4.2:10.2.4.3:10.2.4.4
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.
0
Comment
Question by:WinPE
3 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 250 total points
ID: 22627473
#!/bin/bash
Variable1=10.2.4.1
Variable2=10.2.4.2
Variable3=10.2.4.3
Variable4=10.2.4.4
echo $Variable1:$Variable2:$Variable3:$Variable4 > test.txt

0
 
LVL 48

Assisted Solution

by:Tintin
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.
0
 

Author Closing Comment

by:WinPE
ID: 31502514
Thanks Guys!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Remove Settings button from start menu (Windows 10) 1 234
Annoying "thing" blocks my view 4 113
Launch Process with NOT as Administrator 15 98
AD Cleanup by EmployeeID 11 61
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.

792 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