Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-05-2012
Registered User
 
Join Date: Nov 2009
Posts: 21
Thanks: 6
Thanked 0 Times in 0 Posts
[Solved] Adding time stamp to file name

I have the awk

Code:
awk -F\* '$1=="ST",$1=="SE"{if($1=="ST"){close(f);f="sample" ++i} ; $1=$1; print>f}' OFS=\| <filename>

How to add the time stamp to the file name mentioned as "sample"

Moderator's Comments:
Please view this code tag video for how to use code tags when posting code and data.

Last edited by vbe; 07-05-2012 at 07:15 AM..
Sponsored Links
    #2  
Old 07-05-2012
bartus11's Avatar
Registered User
 
Join Date: Apr 2009
Posts: 3,145
Thanks: 3
Thanked 957 Times in 936 Posts
What format should the timestamp follow?
Sponsored Links
    #3  
Old 07-05-2012
Registered User
 
Join Date: May 2010
Location: Bangalore
Posts: 60
Thanks: 1
Thanked 1 Time in 1 Post

Code:
TIMESTAMP=$( date +%m%d%y.%H%M%S )
FILE="${FILE}.${TIMESTAMP}"

    #4  
Old 07-05-2012
Registered User
 
Join Date: Nov 2009
Posts: 21
Thanks: 6
Thanked 0 Times in 0 Posts
I want the time format as
Code:
date +%m%d%y%H%M%S.

I tried the suggested way, but when doing it I got the files generated as

Code:
${FILE}.${TIMESTAMP}3
${FILE}.${TIMESTAMP}2
${FILE}.${TIMESTAMP}1


Last edited by vbe; 07-05-2012 at 10:37 AM.. Reason: code tags please!
Sponsored Links
    #5  
Old 07-05-2012
bartus11's Avatar
Registered User
 
Join Date: Apr 2009
Posts: 3,145
Thanks: 3
Thanked 957 Times in 936 Posts
Try:
Code:
awk -F\* -vt=`date +%m%d%y%H%M%S` '$1=="ST",$1=="SE"{if($1=="ST"){close(f);f="sample"t"" ++i} ; $1=$1; print>f}' OFS=\| <filename>

The Following User Says Thank You to bartus11 For This Useful Post:
atlantis_yy (07-05-2012)
Sponsored Links
    #6  
Old 07-05-2012
Registered User
 
Join Date: Nov 2009
Posts: 21
Thanks: 6
Thanked 0 Times in 0 Posts
Wonderful, It worked !!!

Thanks a ton.
Sponsored Links
    #7  
Old 07-20-2012
Registered User
 
Join Date: Nov 2009
Posts: 21
Thanks: 6
Thanked 0 Times in 0 Posts
Hi,

I have the code below as


Code:
 
 
cat <filename> | tr '~' '\n' | sed '/^$/ d' | sed "s/*/|/g" > <filename>
awk -F\| -vt=`date +%m%d%y%H%M%S%s` '$1=="ST",$1=="SE"{if($1=="ST"){close(f);f="214_edifile_"t"" ++i} ; $1=$1; print>f}' OFS=\| <filename>

This script works fine if the input file is a smaller size. Actually it replaces some characters and extracts the records starting from ST to SE and writes that in a seperate file. But when trying input file of bigger size the script is giving only partial output.

Can you tell me what could be the reason, is there any size limit of input file in UNIX OS please suggest to resolve.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
file time stamp rajesh_pola Shell Programming and Scripting 4 10-14-2011 06:43 AM
Set date and time stamp of one file to another prvnrk Shell Programming and Scripting 2 12-31-2010 08:57 AM
Change time stamp of a file apskaushik Shell Programming and Scripting 3 10-25-2010 01:12 PM
change the time stamp of file anish19 Shell Programming and Scripting 2 07-01-2008 06:51 AM
how do i put a time stamp in a file name jhamm Shell Programming and Scripting 5 01-29-2007 09:00 AM



All times are GMT -4. The time now is 04:53 AM.