[Solved] How to create a script by combing two files?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] How to create a script by combing two files?
# 1  
Old 01-19-2014
[Solved] How to create a script by combing two files?

I am trying to generate a csv file for utilization of each project directory. there are 10 filesystem and for each filesystem there are 16 directory.
i was trying to create a script so i created two file. one is filesystem and one is project. so file looks like

cat filesystems
Code:
/app1
/app2
/app3
....
....
/app10

cat project
Code:
proj1
proj2
....
....
proj16

Now, I want to create a script so that it will check du for /app1/proj1 then /app1/proj2 then /app1/proj3 and so on till /app1/proj16 and O/P will write to out.csv file

After /app1 completes then again it will start for /app2/proj1 then /app2/proj2 and so on and O/P will write to out.csv file in a new line

and finally script will run for /app10/proj1 then /app10/proj2 and so on till /app10/pro16 and O/P will write to out.csv

need yours help

Last edited by Don Cragun; 01-20-2014 at 12:20 AM.. Reason: Change ICODE tags to CODE tags; add ICODE tags
# 2  
Old 01-20-2014
Try :

Code:
for i in $(cat filesystems_file); do  

          for j in $(cat project_file); do 
                     echo du -h $i/$j
          done
done


OR


Code:
while read filesystems; do 
                 while read project; do 
                              echo du -h $filesystems/$project 
                 done < project_file
done < filesystems_file

if echo is fine then redirect to output file
This User Gave Thanks to Akshay Hegde For This Post:
# 3  
Old 01-20-2014
@Akshay, only the second option wil work if any of the names contain spaces, and only if "$filesystems/$project" is in double quotes..
This User Gave Thanks to Scrutinizer For This Post:
# 4  
Old 01-20-2014
Hello,

Following may also help.

Code:
 
values_check=`paste -d/ first_file_disk second_file_disk`
set -A array_values_check values_check ${values_check}
for i in ${array_values_check[@]}
do
echo "***************************************************"
du $i
echo "***************************************************"
done

Where first_file_disk second_file_disk are two files.


Thanks,
R. Singh
# 5  
Old 01-20-2014
Thanks Akshay It worked ..
Need one more help
When I do cat projects|wc -l then i get O/P as 16
Now I want to create a file (say file1) where exact 16 entries should be there with only date value
example -- when I do cat for file1, it should like below
Code:
cat file1
2014-01-20
2014-01-20
2014-01-20
........
.......
2014-01-20

Date can be defined as
DATE=`date "+%Y-%m-%d"`

Last edited by Scrutinizer; 01-20-2014 at 05:22 PM.. Reason: icode to code tags, removed formatting
# 6  
Old 01-20-2014
In recent shells, try
Code:
for (( i=1; i<=16; i++ )); do echo $DATE >> file1; done

This User Gave Thanks to RudiC For This Post:
# 7  
Old 01-20-2014
Yes, it worked ..!!
instead of giving value as "16" i just want to give input of cat projects|wc -l
example
Code:
DATE=`date "+%Y-%m-%d"`
value=`cat projects|wc -l`
for (( i=1; i<=$value; i++ )); do echo $DATE > File1; done

but it is giving only one entry in file1.

Code:
cat file1
2014-01-20


Last edited by Scrutinizer; 01-20-2014 at 07:03 PM.. Reason: icode tags to code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Python Combing Two Commands

I have been digging deeper into Python and want to make my code as efficient as possible. The less line of code the better so I have been experimenting and wanted to ask the Python gurus if this is possible. So: ... ... In : kbfileurl = re.search('<p>For more information about this... (6 Replies)
Discussion started by: metallica1973
6 Replies

2. Shell Programming and Scripting

How to create or convert to pdf files from csv files using shell script?

Hi, Can anyone help me how to convert a .csv file to a .pdf file using shell script Thanks (2 Replies)
Discussion started by: ssk250
2 Replies

3. Shell Programming and Scripting

[Solved] Help with shell Script ,wait for some files for some time??

Hi All, I have the requirement that ,i have to write a shell script that job has to wait for a 7 touch files created by another application for 4 hours, if i get all 7 touch files ,i have to send a mail that i jobs are completed, if if it is waiting for more than 4 hours i have to send a mail... (2 Replies)
Discussion started by: Pradeep Shetty
2 Replies

4. Shell Programming and Scripting

[Solved] Script to concatenate 2 files with the same number of lines

Hi everyone, I have two files, namely: file1: file1Col1Row1;file1Col2Row1;file1Col3Row1 file1Col1Row2;file1Col2Row2;file1Col3Row2 file1Col1Row3;file1Col2Row3;file1Col3Row3file2: file2Col1Row1;file2Col2Row1;file2Col3Row1 file2Col1Row2;file2Col2Row2;file2Col3Row2... (0 Replies)
Discussion started by: gacanepa
0 Replies

5. Shell Programming and Scripting

[Solved] Get files & delete them by shell script

I want to use my script to get any file then delete it once it transfers to my side , I manage to create below script to generate "list" file which contains all file names in "10.10.1.1" then I made "a.out" file which contains the commands that I want to run it on "10.10.1.1" to get & delete the... (2 Replies)
Discussion started by: arm
2 Replies

6. HP-UX

[Solved] Help with a script to gzip/move files

Hi Please can you help me in writing a script to find files on a specific directory, and of extension "tap" but only of the month of september, gzip and move them to another directory. Your help will be appreciated. (8 Replies)
Discussion started by: fretagi
8 Replies

7. HP-UX

[Solved] HOW TO CREATE VM IN HP UX 11.31

can any one tell me ..HOW TO CREATE VM IN HP UX 11.31 V3... (2 Replies)
Discussion started by: hsejar123
2 Replies

8. Shell Programming and Scripting

Script to create files

Requirement:- SQLs select name from v$datafile; select name from v$controlfile; select name from v$tempfile; select MEMBER from v$logfile; These sqls has to run in one script and o/p of each sql has to write in seperate files.But the o/p is like if we issue select name from... (2 Replies)
Discussion started by: Sanal
2 Replies

9. Shell Programming and Scripting

combing two lines

Hi list, I have to combine two lines and adding the " - " in between. So: Here's sentence A Here's Senctence B Here's sentence A - Here's Senctence B I know how to us SED: sed '$!N;s/\n/ /' for combining tow lines. But how do I insert the " - " correctly? Thanks! Martijn (os... (4 Replies)
Discussion started by: M474746
4 Replies

10. Shell Programming and Scripting

[solved] merging two files and writing to another file- solved

i have two files as file1: 1 2 3 file2: a b c and the output should be: file3: 1~a 2~b 3~c (1 Reply)
Discussion started by: mlpathir
1 Replies
Login or Register to Ask a Question