- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- For loop with two vars
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2012 01:00 PM
01-12-2012 01:00 PM
I have 2 files
file 1
1999
2000
File 2
12457
12458
and 2 directories
ls -al tars_1999
drwxr-xr-x 2 15709 15709 101 Jul 7 2011 12457_1999
drwxr-xr-x 2 15709 15709 101 Jul 7 2011 12458_1999
ls -al tars_2000
drwxr-xr-x 2 15709 15709 101 Jul 8 2011 12457_2000
drwxr-xr-x 2 15709 15709 101 Jul 8 2011 12458_2000
I would like out put to be
file2 number, 1999 size, 2000 size
I have tried:
for x in `more file1`
do
for y in `more file2`
do
du -sh tars_$x/$y_$x
done
done
but it dosen't pick up the $y
also tried
n=1999
for x in 'more file2'
do
du -sh tars_$n/$x_n/*
n=$(( $n + 1 ))
done
but the n never changes.
Of cource this is just a small sample of the data I have
any ideas..
TIA
Solved! Go to Solution.
- Tags:
- for loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2012 01:21 PM - edited 01-12-2012 01:29 PM
01-12-2012 01:21 PM - edited 01-12-2012 01:29 PM
SolutionThe better way to do it is:
for x in $(< file1)
do
for y in $(< file2)
do
du -sk tars_${x}/${y}_${x}
done
done
Also note that HP-UX does not have the '-h' option with 'du'. So 'du -sh' has been changed to 'du -sk' above.
- Tags:
- command substitution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2012 09:22 AM
01-13-2012 09:22 AM
Re: For loop with two vars
Thanks that works great.
Is the any way to output the results to a file
other than ./scriptname > outputfile
I guess I am looking for something with in the script to create the output file
Thanks
- Tags:
- redirect
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2012 09:54 AM
01-13-2012 09:54 AM
Re: For loop with two vars
You can always just redirect the output of the 'du' command.
'du -sk ...' >> outputfile
If you do that, just be sure to append (with the >>) so you don't overwrite the file everytime.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2012 03:47 PM
01-13-2012 03:47 PM
Re: For loop with two vars
>You can always just redirect the output of the 'du' command. 'du -sk ...' >> outputfile
You can also redirect the whole loop:
for x in $(< file1); do
for y in $(< file2); do
du -kxs tars_${x}/${y}_${x}
done
done > outputfile