Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google site



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-29-2008
Registered User
 

Join Date: Jan 2008
Location: Chicago
Posts: 77
merging multiple timestamps into one

Here is a problem that involves looping:

- I have multiple files with same name but different timestamps:
e.g test20080226144525.txt, test20080227144525.txt (can be more
than two files).
- I want to take the collection of these files (e.g test*) and append all its contents to one file.
- This new file with appended contents will be named
test226144525_20080227144525.txt (concatenate timestamps to the filename).

Thanks,

CB
Sponsored Links
  #2 (permalink)  
Old 03-03-2008
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 6,152
I see one problem at least. There are limits to filename length on a lot of unix filesystems.
If you have more than two files, you could start getting in trouble. Some filesystems may be okay. I dunno what filesystems you have.

That said, try something this ksh script:

Code:
#!/bin/ksh
set -A arr test*
cat ${arr[*]} > tmpfile
newname="test"
for i in test*
do
     t1=${i#test}
     t2=${t1%.txt}
     newname=$newname"_$t2"
done
newname=$newname".txt"
mv tmpfile $newname

  #3 (permalink)  
Old 03-03-2008
Registered User
 

Join Date: Feb 2005
Posts: 59
Hi,

I think you can cut the changing part of the names with "cut -c"
then use "xargs" with "echo" to obtain single line and then "tr -d" to remove spaces.

But consider that with names like you presented you can easily generate too long filename.

Regards,
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 Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
timestamps chriss_58 Shell Programming and Scripting 1 05-30-2008 06:12 AM
Difference between two timestamps raman1605 Solaris 8 08-05-2007 08:54 PM
merging multiple log files jack1981 Shell Programming and Scripting 3 10-03-2006 09:50 AM
Unix timestamps hamsasal UNIX for Dummies Questions & Answers 3 09-07-2006 10:03 AM
Find command to get the timestamps nguda Shell Programming and Scripting 8 03-24-2003 12:35 PM



All times are GMT -4. The time now is 05:19 PM.


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-2010. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0