Sponsored Content
Top Forums UNIX for Dummies Questions & Answers extracting and using date from filenames in a loop Post 302230351 by badg3r on Friday 29th of August 2008 06:24:23 AM
Old 08-29-2008
Data extracting and using date from filenames in a loop

HIya,

Having a dumb day whilst writing an archive process in Shell want to extract from the filename the date and archive into tar files based on this, I don't want to use mtime as it may not be the actual file date.

The files are

-rw-rw---- 1 user admin 100 Aug 29 11:10 Jav_Transmission_20080826.dat
-rw-rw---- 1 user admin 100 Aug 29 11:10 Jav_Transmission_20080827.dat
-rw-rw---- 1 user admin 100 Aug 29 11:11 Jav_Transmission_20080828.dat
-rw-rw---- 1 user admin 100 Aug 29 11:11 Jav_Transmission_20080829.dat

so for each of the days in the below dir I want to find a way to sort of

for dates in `ls -l |extract distinct file date in thias directory`

tar -cvf ${dates}.tar *${dates}*.dat
mv ${dates}.tar /arc

done

So of thing, any help gratefully received.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

changing filenames in a directory to a number within a loop

hey guys. i'm new to shell scripting but not new to programming. i want to write a script that will take all the files in the current directory that end with a particular filetype and change all their names to a number in order. so, it would take all the jpg files and sort them in alphabetical... (30 Replies)
Discussion started by: visitorQ
30 Replies

2. Shell Programming and Scripting

Perl: Extracting date from file name and comparing with current date

I need to extract the date part from the file name (20080221 in this ex) and compare it with the current date and delete it, if it is a past date. $file = exp_ABCD4_T-2584780_upto_20080221.dmp.Z really appreciate any help. thanks mkneni (4 Replies)
Discussion started by: MKNENI
4 Replies

3. Shell Programming and Scripting

loop through numbered filenames

Hi I'm very new to this script thing, so please be gentle. I am trying to get a command - the mach2qtl command in the code below - to loop through a set of files. Each command should take the same two .dat and .ped files, but the .mlinfo and .mlprob files with filenames including 'chrom1' ... (7 Replies)
Discussion started by: polly_falconer
7 Replies

4. Shell Programming and Scripting

Whitespace in filenames in for loop in bash script

I'm trying to search all .odt files in a directory for a string in the text of the file. I've found a bash script that works, except that it can't handle whitespace in the filenames. #!/bin/bash if ; then echo "Usage: searchodt searchterm" exit 1 fi for file in $(ls *.odt); do ... (4 Replies)
Discussion started by: triplemaya
4 Replies

5. Shell Programming and Scripting

How to extract date out of this filenames

I have filenames filenameA_fg_MMDDYY.tar.gz filenameASPQ_fg_MMDDYY.tar.gz filenameAFTOPHYYINGH_fg_MMDDYY.tar.gz filenameAGHYSW_fg_MMDDYY.tar.gz Is there a way I can extract the date out of these filenames? Thanks in advance (2 Replies)
Discussion started by: RubinPat
2 Replies

6. Shell Programming and Scripting

Extracting filenames

Hi I need to pull out the name of the file from the path. See, here is my loop that gets the files: dsxdir="/var/local/dsx/import" for dsxfile in $dsxdir/*.dsx; do dsxlog $reverb --info --module="$module" "$dsxfile" $dsximp $norule $oprange --dsn=$dsn --dbname=$dbname... (6 Replies)
Discussion started by: ladyAnne
6 Replies

7. UNIX for Dummies Questions & Answers

Searching by date range from filenames

Hello all, i have tons of files in folder named like this (yyyymmdd): bookcollection20100729 bookcollection20100730 bookcollection20100731 bookcollection20100801 bookcollection20100802 etc. I need to find files with date range in there names lets say from 2010.07.30 - 2010.08.02 ... (10 Replies)
Discussion started by: Whit3H0rse
10 Replies

8. Shell Programming and Scripting

Generate filenames in a loop

Hi all, I want to generate output files in a loop, run the same command on the same input file 1000 times and output in files with a new name each time, maybe a number appended to it. The output will be different each time as I`m sampling randomly from the input file. I want to do the... (3 Replies)
Discussion started by: newbie83
3 Replies

9. Shell Programming and Scripting

For/While Loop to Increment Filenames in a Script

Daily stupid question. I want to increment the file name everytime the script is run. So for example if the filename is manager.log and I run the script, I want the next sequence to be manager.log1. So to be clear I only want it to increment when the script is executed. So ./script... (10 Replies)
Discussion started by: metallica1973
10 Replies

10. Shell Programming and Scripting

Appending date to UNIX Filenames

Hello, I have a file name in the below format and have to append the date as _$currdate. kchik_UK_lo.txt_$currdate. The above should be the format and I dont want to put entire filename as above in the code, but it should give me the output as the above filename.Can anyone please help... (7 Replies)
Discussion started by: harika03
7 Replies
TRACE-CMD-RESTORE(1)													      TRACE-CMD-RESTORE(1)

NAME
trace-cmd-restore - restore a failed trace record SYNOPSIS
trace-cmd restore [OPTIONS] [command] cpu-file [cpu-file ...] DESCRIPTION
The trace-cmd(1) restore command will restore a crashed trace-cmd-record(1) file. If for some reason a trace-cmd record fails, it will leave a the per-cpu data files and not create the final trace.dat file. The trace-cmd restore will append the files to create a working trace.dat file that can be read with trace-cmd-report(1). When trace-cmd record runs, it spawns off a process per CPU and writes to a per cpu file usually called trace.dat.cpuX, where X represents the CPU number that it is tracing. If the -o option was used in the trace-cmd record, then the CPU data files will have that name instead of the trace.dat name. If a unexpected crash occurs before the tracing is finished, then the per CPU files will still exist but there will not be any trace.dat file to read from. trace-cmd restore will allow you to create a trace.dat file with the existing data files. OPTIONS
-c Create a partial trace.dat file from the machine, to be used with a full trace-cmd restore at another time. This option is useful for embedded devices. If a server contains the cpu files of a crashed trace-cmd record (or trace-cmd listen), trace-cmd restore can be executed on the embedded device with the -c option to get all the stored information of that embedded device. Then the file created could be copied to the server to run the trace-cmd restore there with the cpu files. If *-o* is not specified, then the file created will be called 'trace-partial.dat'. This is because the file is not a full version of something that trace-cmd-report(1) could use. -t tracing_dir Used with -c, it overrides the location to read the events from. By default, tracing information is read from the debugfs/tracing directory. -t will use that location instead. This can be useful if the trace.dat file to create is from another machine. Just tar -cvf events.tar debugfs/tracing and copy and untar that file locally, and use that directory instead. -k kallsyms Used with -c, it overrides where to read the kallsyms file from. By default, /proc/kallsyms is used. -k will override the file to read the kallsyms from. This can be useful if the trace.dat file to create is from another machine. Just copy the /proc/kallsyms file locally, and use -k to point to that file. -o output' By default, trace-cmd restore will create a trace.dat file (or trace-partial.dat if -c is specified). You can specify a different file to write to with the -o option. -i input By default, trace-cmd restore will read the information of the current system to create the initial data stored in the trace.dat file. If the crash was on another machine, then that machine should have the trace-cmd restore run with the -c option to create the trace.dat partial file. Then that file can be copied to the current machine where trace-cmd restore will use -i to load that file instead of reading from the current system. EXAMPLES
If a crash happened on another box, you could run: $ trace-cmd restore -c -o box-partial.dat Then on the server that has the cpu files: $ trace-cmd restore -i box-partial.dat trace.dat.cpu0 trace.dat.cpu1 This would create a trace.dat file for the embedded box. SEE ALSO
trace-cmd(1), trace-cmd-record(1), trace-cmd-report(1), trace-cmd-start(1), trace-cmd-stop(1), trace-cmd-extract(1), trace-cmd-reset(1), trace-cmd-split(1), trace-cmd-list(1), trace-cmd-listen(1) AUTHOR
Written by Steven Rostedt, <rostedt@goodmis.org[1]> RESOURCES
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/trace-cmd.git COPYING
Copyright (C) 2010 Red Hat, Inc. Free use of this software is granted under the terms of the GNU Public License (GPL). NOTES
1. rostedt@goodmis.org mailto:rostedt@goodmis.org 06/11/2014 TRACE-CMD-RESTORE(1)
All times are GMT -4. The time now is 01:46 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy