Script to generate csv file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to generate csv file
# 8  
Old 08-09-2011
ahh yes, on HPUX that -ls option on find is missing. Stupid HPUX Smilie.

Let me see if I can edit that code from pludi to run on hpux.
# 9  
Old 08-09-2011
Funny though; when I do a "man find" it shows the "-ls" option.

Is the "man" just a "show all options but some may not work on your OS" listing?

Also; in the code; where am I actually creating the CSV file? I was thinking that a script to do what I am looking to do would be much larger, not that I would take a lrage script over a short one; just that is seems so streamlined...if it actually does what I need it to do.

G
# 10  
Old 08-09-2011
Here you go.
Code:
find /tmp -type f -perm 777 -exec ls -al {} \;|while read a b c d e f g h 
do 
filepath=`echo $h|awk '{print $2}'` 
filename=`echo $filepath|awk -F "/" '{print $NF}'` 
echo "`hostname`;$c;$d;$filename;$filepath" 
done

This User Gave Thanks to dude2cool For This Post:
# 11  
Old 08-09-2011
Super; I will give it a try a little later.

Will get back to you via this forum either way.

Regards
G
# 12  
Old 08-09-2011
Quote:
Originally Posted by dude2cool
Here you go.
Code:
find /tmp -type f -perm 777 -exec ls -al {} \;|while read a b c d e f g h 
do 
filepath=`echo $h|awk '{print $2}'` 
filename=`echo $filepath|awk -F "/" '{print $NF}'` 
echo "`hostname`;$c;$d;$filename;$filepath" 
done

To create the csv file, you would need to redirect the last echo statement to a filename. So instead of spitting out on the terminal, it will redirect output to a file. But you can redirect, once you are satisfied with that you see on screen.

---------- Post updated at 10:27 AM ---------- Previous update was at 10:25 AM ----------

and remember to change find /tmp to whatever directory you need to search. I hardcoded /tmp in my code, since I was testing against /tmp.
# 13  
Old 08-09-2011
Thanks dude2cool;

I will be working on it now. Will let you know.

Thanks to all for your advise\input; greatly appreciated.

Regards
G

---------- Post updated at 03:19 PM ---------- Previous update was at 01:07 PM ----------

Hey dude2cool;

from a standpoint of content of a line (see below ex.); it's fine:
pike;root;sys;bat00125.log;/tmp/bat00125.log

However; I put the "redirect to a file" option in (see below):
echo "`hostname`;$c;$d;$filename;$filepath" >testfile

But the contents of the "testfile" when I cat it is one record. I tried putting in a /n like this:
echo "`hostname`;$c;$d;$filename;$filepath \n" >testfile

But no luck.

Any ideas? Also; can I replace the ";" in the record with ","?

Regards & thanks
Giuliano
# 14  
Old 08-09-2011
@dude2cool: Thanks for fixing it up. Although I think that both dirname and basename are shell builtins, but I could be wrong.

@gvolpini: A single bracket (>) will overwrite the file on each successive iteration. Double them to append instead (>>)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Generate .csv/ xls file report

There can be thousand of .ksh in a specific directory where sql files are called from ksh. Requirement is to loop through all the files content and generate a report like below: Jobname Type type sqlname gemd1970 sql daily tran01 gemw1971 sql weekly ... (6 Replies)
Discussion started by: vedanta
6 Replies

2. Shell Programming and Scripting

Script to generate .csv file

Dears,I need your help in this, I have to create a report based on the output file generated by another program. I want to write a shell script for this. The output file generated every 15 minutes but i can’t open it until the end of day so the script will get the file as an input the file will be... (8 Replies)
Discussion started by: abdul2020
8 Replies

3. Shell Programming and Scripting

Script to generate csv file

Dears, I am new in shell world and I need your help in this, I have to create a report based on the output file generated by another program. I want to write a shell script for this. The output file generated every 15 minutes but i can’t open it until the end of day so the script will get the... (3 Replies)
Discussion started by: abdul2020
3 Replies

4. Shell Programming and Scripting

BASH script to parse XML and generate CSV

Hi All, Hope all you are doing good! Need your help. I have an XML file which needs to be converted CSV file. I am not an expert of awk/sed so your help is highly appreciated!! XML file looks like this: <l:event dateTime="2013-03-13 07:15:54.713" layerName="OSB" processName="ABC"... (2 Replies)
Discussion started by: bhaskar_m
2 Replies

5. Shell Programming and Scripting

Read a CSV file and generate SQL output

Friends, This is what I need: I will pass a CSV file as an input, and I want my shell to be reading that CSV file, and based on the parameters it should generate SQLs and write those SQL in a different file in the same location. I'm new to Shell scripting. I'm currently working on a... (25 Replies)
Discussion started by: Ram.Math
25 Replies

6. Shell Programming and Scripting

to read a CSV file and generate SQL output

Friends, This is what I need: I will pass a CSV file as an input, and I want my shell to be reading that CSV file, and based on the parameters it should generate SQLs and write those SQL in a different file in the same location. I'm new to Shell scripting. I'm currently working on a... (1 Reply)
Discussion started by: Ram.Math
1 Replies

7. Shell Programming and Scripting

Need to generate .csv file

I have a csv file with the following data Please find the attachment - zip ... (6 Replies)
Discussion started by: vaas
6 Replies

8. Shell Programming and Scripting

need help in Parsing a CSV file and generate a new output file

Hi Scripting Gurus, I am trying to parse a csv file and generate a new output file. The input file will be a variable length in turns of rows and columns. output file will have 8 columns. we have three columns from the header for each set. just to give little bit more clarification each row... (15 Replies)
Discussion started by: vkr
15 Replies

9. UNIX for Dummies Questions & Answers

generate CSV file using AWK script

Hi guys I have a text report that consists of text in some parts and data in some parts. e.g Report for changes in cashflows No changes were found Report for changes in Bills deal_num deal_date trader maturity log_creator DF_234 20-5-2008 tman 20-5-2009 tman... (2 Replies)
Discussion started by: magikminox
2 Replies

10. Shell Programming and Scripting

Generate csv file

I have a file which has some thousand records in the following format File: input.txt -> <option value="14333">VISWANADH VELAMURI</option> <option value="17020">VISWANADHA RAMA KRISHNA</option> I want to generate a csv file from the above file as follows File: output.txt -> ... (4 Replies)
Discussion started by: rahulrathod
4 Replies
Login or Register to Ask a Question