LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-19-2007, 11:26 PM   #1
dwarf007
Member
 
Registered: Sep 2004
Location: Malaysia
Posts: 181

Rep: Reputation: 30
how to echo whole string to a file?


Is there anyone know how to echo whole string to a file?

I am trying to echo the below sting into a file, but the output will be DATETIME=070620115242

DATETIME=`date +"%y%m%d%H%M%S"`

Appreciate someone can help on this : )
 
Old 06-19-2007, 11:43 PM   #2
SlackDaemon
Member
 
Registered: Mar 2006
Distribution: RedHat, Slackware, Experimenting with FreeBSD
Posts: 222

Rep: Reputation: 30
Use the redirection operators > or >>. The latter will append to a file while the first will overwrite its contents:

DATETIME=`date +"%y%m%d%H%M%S"`
echo DATETIME=$DATETIME > file.txt
 
Old 06-20-2007, 12:00 AM   #3
dwarf007
Member
 
Registered: Sep 2004
Location: Malaysia
Posts: 181

Original Poster
Rep: Reputation: 30
It still occurs the same output in the file "DATETIME=070620121353"

I need the below exact line exist in the file.
DATETIME=`date +"%y%m%d%H%M%S"`

Is there any way to do it?
 
Old 06-20-2007, 12:11 AM   #4
SlackDaemon
Member
 
Registered: Mar 2006
Distribution: RedHat, Slackware, Experimenting with FreeBSD
Posts: 222

Rep: Reputation: 30
echo 'DATETIME=`date +"%y%m%d%H%M%S"`' > file.txt

notice both ` and ' were used
 
Old 06-20-2007, 02:38 AM   #5
dwarf007
Member
 
Registered: Sep 2004
Location: Malaysia
Posts: 181

Original Poster
Rep: Reputation: 30
Thanks a lot, it works now.
Appreciate your help so much : )
 
Old 06-20-2007, 03:44 AM   #6
Dr_Death_UAE
Member
 
Registered: Jul 2005
Location: U.A.E
Distribution: FreeBSD,Fedora,Solaris,AIX
Posts: 168

Rep: Reputation: 30
btw, "echo -n > filename" will empty the file.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
c++ file string from text file into 1d array ak3 Programming 16 12-29-2006 09:45 AM
ls | echo, I got blank, why can't echo take the 2nd seat in a pipeline? elinuxqs Linux - Newbie 6 11-24-2006 08:25 AM
How do I echo to both standard out and to a file? Br. Nicholas Linux - General 11 10-12-2004 03:09 PM
echo data in to a file xlord Linux - Newbie 3 05-29-2004 12:19 PM
Using echo to output a string to a file with forward slashs chrisk5527 Linux - General 15 06-21-2003 02:04 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:39 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