The UNIX and Linux Forums  

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
getting date from timestamp pavan_test UNIX for Dummies Questions & Answers 2 09-28-2006 01:01 PM
get a file date/timestamp alex31 UNIX for Dummies Questions & Answers 3 12-22-2005 10:06 AM
renaming the file with the timestamp ajubi Shell Programming and Scripting 6 12-05-2005 06:21 AM
how attached date when renaming log file ukadmin Shell Programming and Scripting 2 08-11-2003 11:42 AM
Creating file with date/timestamp in it ccpjr29 Shell Programming and Scripting 7 03-04-2002 04:14 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-05-2008
Sunitha_edi82 Sunitha_edi82 is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 17
File renaming with date timestamp

Hi,

This is my script:

#! /usr/bin/ksh
cd /app/chdata/workflow/suppl/esoutput/spd/testing
for file in /app/chdata/workflow/suppl/esoutput/spd/testing
do
sort *.txt | awk '{ file=substr($0,1,2)".txt"; print >> file }'
mv *.txt file_`date +"%Y%m%d%H%M%S"`.txt
done


Here, I am trying to rename all the files say *.txt to *_date.txt.

However, Its throwing an error.

Please help.

Regards,
Sunitha
  #2 (permalink)  
Old 08-05-2008
ynilesh's Avatar
ynilesh ynilesh is offline
Registered User
  
 

Join Date: Oct 2007
Location: Bangalore, India.
Posts: 222
what error ?

- nilesh
  #3 (permalink)  
Old 08-05-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
You probably mean


Code:
for file in *.txt; do
  mv "$file" file_`date +"%Y%m%d%H%M%S"`.txt
done

The sort | awk seems to be entirely unrelated to this problem. It should not be inside the for loop if you don't really mean for it to also operate on each file in *.txt separately (then similarly using "$file" as the argument to sort instead of *.txt).
  #4 (permalink)  
Old 08-05-2008
Sunitha_edi82 Sunitha_edi82 is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 17
Thanks for the reply
Closed Thread

Bookmarks

Tags
date timestamp, file rename

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 08:31 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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