?
Solved

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

Posted on 2008-10-02
3
Medium Priority
?
1,281 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 1000 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 1000 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

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

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

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…
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

765 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