FILE_ID EXTRACTION FROM FILE NAME AND SAVE IT IN CSV FILE AFTER LOOPING THROUGH EACH FOLDERS
My files are located in UNIX Server, i want to extract file_id and file_name from each file .and save it in a CSV file. How do I do that?
I have folders in unix environment, directory structure is structured as follows
year folder -> inside 12 months folders -> inside 30/31 days folders
I ran ls command folder
year as follows
2009 2010 2011 2012
I ran cd command for year 2012
I ran ls command for 2012 year folder
then I ran command for september
there are folders for each year like 2009,2010,2011 and 2012
and folder has 12 folders for each months like 01,02,03,04,05,06,07,08,09,10,11,12
and each month folder has 31 folders for days like 1,2,3, etc... 29,30,31
inside each day folder has files..
the file name is as follows,
I want to have one csv file and that file needs to have two columns , one is for file_id and
second field is for file name.
to obtain file_id value ,loop through each folders and get file name, then read file name and
get substring between "sasmm_fsbc_durds_id000" and _t and store it in file_id column and store
file name in file_name column.
in above example for file sasmm_fsbc_durds_id00020532_t20100313192606.dat.trnsfr.gz
read file name sasmm_fsbc_durds_id00020532_t20100313192606.dat.trnsfr.gz
cut 20532 and save it in a file_id clumn and the whole file name in second column = sasmm_fsbc_durds_id00020532_t20100313192606.dat
CSV file will look like
file_id is to be cut from the file name , if you look at the file name closely, you can see;
after 000 , file_ids in above file name examples , they are 20532 and 20513.
How do I loop through year 2012 and 12 months folders and 31 days folders inside it and create
csv file which has data as shown above?
I am very new unix, please help me out.. If you provide a code , that would be great..
thanks..
output CSV file look like this
Last edited by Corona688; 09-14-2012 at 12:53 PM..
To keep the forums high quality for all users, please take the time to format your posts correctly.
First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)
Selective use of color to highlight a single word or phrase can be useful at times, but large blocks of color, in general, makes the forums harder to read, especially bright colors like red.
Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.
Hi Everyone,
I am getting strange behavior, same script runs fine without any error in one AIX machine, whereas on another it is throwing this error "0403-057 Syntax error at line 399 : `"' is not matched", I also ran the script in debug mode.
This is the output, still doesn't say anything.... (2 Replies)
Hi,
While executing my code i am getting below Error:
./check_disk1: 0403-057 Syntax error at line 55 : `(' is not expected.
My code is :
#!/bin/ksh
PROGNAME=`basename $0`
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
OS=$(uname)
AWK="/usr/bin/awk"... (6 Replies)
I am getting the following error when I am running a script in ksh when trying to execute an if statement comparing two numerical values
tstmb.sh: 1.5321e+08: 0403-057 Syntax error
Below is my code snippet.
#!/bin/ksh
set -x
TODAY=$(date +%y%m%d)
for file in $(ls -rt *.log | tail... (11 Replies)
Hi,
I am new to shell scripting.i am trying to mail after my backup completed.
Here is my shell script:
if ; then
egrep (ERROR|error|Error|RMAN-) ${/backup/RMANBKUP/spool/shelltest.log} > /dev/null
if ; then
RESULT_MSG=WARNING: Errors occurred during the ${ORACLE_SID} Rman... (3 Replies)
i dont know where m i mistaking.. please help me out with this issue :(
thanks in advance:rolleyes:
one_main()
{
a=100
while ;
do
clear
echo "##############################################"
echo ":: CURRENTLY YOU ARE IN RC AND OC MARKING ::"
echo... (1 Reply)
Hi
I am getting error 'ksh: 0403-057 Syntax error: `done' is not expected.' when running below script any one can provide inputs on this.
------------------------
if
then
echo "Report Name |Modification Date|Report File Size|Owner" >SOX_`date +'%Y%m%d'`
while read line
do... (2 Replies)
Can someone please tell me wht is wrong with the following peice of code?
I keep getting the following error -
0403-057 Syntax error at line 52 : `)' is not expected.
case "${option_count}" in
1) java -Xms256m -Xmx1536m "${APPLNAME}" "${ACTION_TYPE}" > "${LOGFILE}" 2>... (2 Replies)
Hi All,
I got a script from one of the unix forums for reporting on filesystem usage and wanted to use it but it keeps giving me the following error.
0403-057 Syntax error at line 70
The script is shown below.
Pls help as I am new to UNIX.
# set -x
# D I S K S P A C E . S H
#
#... (2 Replies)