- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Checking file contents
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
Forums
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
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
06-02-2002 10:02 PM
06-02-2002 10:02 PM
I have the following 2 files, which is the form:
#cat f1
/fs12/nwd.cr.24
/fs12/nwd.des.mem
/fs13/nwd.fclk.45
/fs14/nwd.cr.256
/fs37/nwd.srtl.pv
#cat f2
/fs12/nwd.cr.24
/fs12/nwd.des.mem
/fs11/nwd.shark.pv
/fs36/nwd.srtl.rtl
/fs37/nwd.srtl.pv
whereby files f1 and f2 contains lists of filesystems residing on 2 remote machines, A and B respectively.
I was wondering, how do I read the contents of these files, and place them into 2 seperate arrays in Bourne/C-shell?
I would like to compare every index of the 2 arrays to see if they are similar. If similar, then I would like to rcp them from machine A into machine B, else do nothing.
Can someone help me out in this matter?
Thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2002 11:03 PM
06-02-2002 11:03 PM
Re: Checking file contents
you can put the output of any command as value into a variable using command substitution:
array[0]=`cat f1`
array[1]=`cat f2`
After this, you can compare the output of your cat- command or whatever you want to do.
Allways stay on the bright side of life!
Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2002 11:11 PM
06-02-2002 11:11 PM
Re: Checking file contents
Does the statement array[0]='cat f1' places the entire entries/contents of the file f1 into array[0]?
So how do I compare each of the contents/entries of file f2, which is placed into array[1]?
I would like to have 2 seperate arrays, each holding the entries of files f1 and f2 respectively.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2002 11:32 PM
06-02-2002 11:32 PM
Re: Checking file contents
please use backticks for the command substitution to get it work. Then the answer is YES, the output of your cat- command ist put into an array. If you want to put single lines into variables, you need a loop construction for this. The awk- command can help you here.
Allways stay on the bright side of life!
Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2002 11:44 PM
06-02-2002 11:44 PM
SolutionTry this
integer num=0
for i in `cat f1`
do
array[$num]=$i
(( num = $num + 1 ))
done
integer num2=0
for i in `cat f2`
do
array2[$num2]=$i
(( num2 = $num2 + 1 ))
done
sw=ok
integer F=0
for i in ${array[@]}
do
if [ ${array[$F]} = ${array2[$F]} ]
then
ok=ok
else
ok=nook
exit;
fi
(( F = $F + 1 ))
done
if [ $ok = "ok" ]
then
echo " are the same copying"
integer F1=0
for i in ${array[@]}
do
rcp hosta:${array[$F1]} hostb:${array2[$F1]}
(( F1 = $F1 + 1 ))
done
fi
Hope this helps
Justo.