The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Insert Text at begining of file netwolf High Level Programming 3 05-27-2008 12:20 PM
How to insert text in the middle of a file kartikkumar84@g UNIX for Dummies Questions & Answers 6 05-10-2008 02:35 PM
insert text into top of file jimbob Shell Programming and Scripting 1 09-22-2006 05:46 PM
SED- Insert text at top of file MBGPS Shell Programming and Scripting 12 07-03-2002 09:48 AM
insert text into a dinamic file sunbird UNIX for Dummies Questions & Answers 2 11-05-2001 10:58 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-09-2007
bucci bucci is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 81
Lightbulb insert some text to a file log

Hi experts,

i have some problem with inserting text to a file, i have a file named test.log output like this :

11111 22222 33333 44444 55555

i want to insert date into the file test.log, expected output is :

20070501 11111 22222 33333 44444 55555


any idea?

please help

Thank you

Regards,

bucci
  #2 (permalink)  
Old 05-09-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Code:
perl -i -ne ' print "20070501 $_" ' file
  #3 (permalink)  
Old 05-09-2007
ahmedwaseem2000 ahmedwaseem2000 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Bangalore
Posts: 219
alternatively you could use

Code:
dt=$(date +%Y%m%d)
sed '1,$s/^/'$dt'/g file
  #4 (permalink)  
Old 05-09-2007
bucci bucci is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 81
Hi anbu and ahmed,

thank you for your response

it work for me now

Regards,

bucci
  #5 (permalink)  
Old 05-09-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,930
Quote:
Originally Posted by ahmedwaseem2000
alternatively you could use

Code:
dt=$(date +%Y%m%d)
sed '1,$s/^/'$dt'/g file

should be a typo..
it should be
sed '1,$s/^/'$dt' /g' file

(added a space after '$dt' as per the OP's output )

or

just this would do,
sed '/^/'$dt' /g' file
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 05:55 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0