04-13-2011
Extract variables from filenames and output to file
I need some help. I have a list of files (thousands) and would like to extract some variables from the file name and save that to a file
The list of files look like:
Quote:
e20012110129_xform_azisum_mlt_2.25_0.50.txt
e20012130535_xform_azisum_mlt_2.25_0.50.txt
e20012160231_xform_azisum_mlt_2.25_0.50.txt
e20012210636_xform_azisum_mlt_2.25_0.50.txt
e20012230332_xform_azisum_mlt_2.25_0.50.txt
e20012240738_xform_azisum_mlt_2.25_0.50.txt
e20012270434_xform_azisum_mlt_2.25_0.50.txt
e20012320839_xform_azisum_mlt_2.25_0.50.txt
I am trying to write the following script but I am stuck at how I can get thevariables 'doy' and 'yr' from each file and then combine into one file with two columns "yr doy' then write that to a file
Quote:
#! /bin/bash
# if there's an error, using a number greater than 0 will exit with that
# number
EXIT_ON_ERROR=1
IFS=$'\n'
dirctry=~/Research/selected
cd $dirctry/
# process the rest of files
ls *.txt | sort -rn > imputFiles.dat
while read fliz ; do
if [ -e "$filz" ] ; then
# Extract a part of the filename for naming the output file
filenme=$filz
doy=`echo ${filenme:5:3}`
yr=`echo ${filenme:1:4}`
hr=`echo ${filenme:8:2}`
min=`echo ${filenme:10:2}`
# I need to get "yr" and "doy" for each file combine into one file with two columns
and output that to a file like shown below
else
echo "ERROR: Couldn't open file '$filz'" >&2
if [ $EXIT_ON_ERROR -gt 0 ] ; then
exit $EXIT_ON_ERROR
fi
fi
done < imputFiles.dat
And the required output is
Quote:
2001 211
2001 213
2001 216
2001 221
2001 223
2001 224
2001 227
2001 232
Please any help and ideas will be highly appreciated
Thank you
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi! I'm somewhat new to Unix (I use it to fiddle, but not seriously), and at my work I have come to use it quite a bit. My question is this:
I want to create a script to take the tedium out of repetitious tasks. However, I need to pass a file name into the script in order for it to work.
... (5 Replies)
Discussion started by: MrToast
5 Replies
2. Shell Programming and Scripting
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
3. Shell Programming and Scripting
Hi all,
I'm using awk in a .ksh script to split one file by line prefix into different files (up to 4). The files are named after the prefix in the line, and a sequence no.
Is there any way to get the filenames in to variables too? I need _ftpfile1, _ftpfile2, _ftpfile3 and _ftpfile4 which are... (2 Replies)
Discussion started by: spidermike
2 Replies
4. Shell Programming and Scripting
Hi Folks,
I've searched for this for quite a while, but can't find any solution - hope someone can help.
I have various files with standard headers. eg.
<HEADER>
IP: 1.2.3.4
Username: Joe
Time: 12:00:00
Date: 23/05/2010
</HEADER>
This
is
a
test
and this part can be any size... (6 Replies)
Discussion started by: damoske
6 Replies
5. Shell Programming and Scripting
Greetings.
I am trying to do a script that will do some file copying for me. Unfortunately I have spaces in the directory names (which I cannot change) and the result is someone hard to achieve in shell scripts. I have searched everywhere on the web but does not manage to find the answer to... (3 Replies)
Discussion started by: Mr.Glaurung
3 Replies
6. Shell Programming and Scripting
Hi All,
I have a file, let's call it "info.tmp" that contains data like this ..
ABC123456
PCX333445
BCD789833
I need to read "info.tmp" and for each line add strings in a way that the final output is
put /logs/ua/dummy.trigger 'AAA00001.FTP.XXX.BLA03A01.xxxxxx(+1)'
where XXX... (5 Replies)
Discussion started by: Andy_ARG
5 Replies
7. Shell Programming and Scripting
Hi Unix Gurus,
In a script, I am trying to extract unique text from a set of filenames.
I have certain files like below in a directory:
OPEN_INV_01012011.xls
OPEN_INV_01022011.xls
OPEN_INV_01032011.xls
CLOSE_INV_01012011.xls
CLOSE_INV_01022011.xls
I need to extract just "OPEN_INV_" ... (4 Replies)
Discussion started by: shankar1dada
4 Replies
8. UNIX for Dummies Questions & Answers
Hello All,
Here is seeking a bit of help in trying to solve a problem.
I am required to create a csv file as shown below:
output.csv ->
output_1,output_2,output_3,...,output_<N>
filename1:20,filename2:30,filename3:30,...,filename<N>:30
by listing output_1, output_2,... , output<N> as... (3 Replies)
Discussion started by: vkumbhakarna
3 Replies
9. Shell Programming and Scripting
I've got a file that looks like this (spaces before first entries intentional):
12345650-000005000GL140227 ANNUAL HELC FEE EN
22345650-000005000GL140227 ANNUAL HELC FEE EN
32345650-000005000GL140227 ANNUAL HELC FEE EN
I want to read through the file line by line,... (6 Replies)
Discussion started by: Scottie1954
6 Replies
10. UNIX for Beginners Questions & Answers
Hi All
I have 2 file . I need match the files based on key and then form a third file which have the matching values
FILE1:
10264;K*AD
10265;K*AIR
10266;K*AUTO
10267;K*BABY
10268;K* FOOD
FILE2:
10264;1055.83
10265;716.94
10267;331.80
10268;23283.33
OUTPUT (Needed)... (2 Replies)
Discussion started by: arunkumar_mca
2 Replies
LEARN ABOUT DEBIAN
file-roller
file-roller(1) General Commands Manual file-roller(1)
NAME
file-roller - archive manager for GNOME
SYNOPSIS
file-roller [OPTIONS...] [FILE...]
DESCRIPTION
File Roller is a graphical interface to archiving utilities such as tar and zip.
It supports most common operations such as creating, modifing and extracting files from an archive. You can also view the contents of an
archive and open files contained in the archive.
OPTIONS
-a, --add-to=ARCHIVE
Add files to the specified archive and quit the program
-d, --add FILE
Add files asking the name of the archive and quit the program
-e, --extract-to=FOLDER
Extract archives to the specified folder and quit the program
-f, --extract
Extract archives asking the destination folder and quit the program
-h, --extract-here
Extract archives using the archive name as destination folder and quit the program
--default-dir=FOLDER
Default folder to use for the '--add' and '--extract' commands
--force
Create destination folder without asking confirmation
This program also accepts the standard GNOME and GTK options.
AUTHORS
file-roller is written by Paolo Bacchilega <paolo.bacch@tin.it>.
This manual page was written by Sven Arvidsson <sa@whiz.se>, for the Debian project (but may be used by others).
SEE ALSO
gtk-options(7), gnome-options(7)
The online documentation available through the program's Help menu.
GNOME
2007-09-27 file-roller(1)