- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- merging lines
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
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
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
тАО08-18-2005 06:39 AM
тАО08-18-2005 06:39 AM
I'm listing all the patches on 3 separate servers into 3 files. 1D 9D and 1A
For simplicity we'll say the files have the following content.
File 1D.out 9D.out 1A.out
------- -------- ---------
patchA patchA patchB
patchB patchC patchC
I want the output to be: (FS=| and each colums 2-4 represent if the patch was found in a source file.
patchA|yes|yes|no # Found in 1D,9D and not 1A
patchB|yes|no|yes
patchC|yes|no|no
Where "yes" and "no" represent if the patch was found in the source file.
I want to write this in POSIX / KSH and not Perl since the folks I work with aren't Perl programmers.
How can I merge these records to achieve this result?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-18-2005 06:52 AM
тАО08-18-2005 06:52 AM
Re: merging lines
Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-18-2005 07:04 AM
тАО08-18-2005 07:04 AM
Re: merging lines
cat 1D 9D 1A |sort |uniq |while read PATCH ;do
LINE="$PATCH"
if [ -n "`grep $PATCH 1D`" ] ;then
LINE="$LINE|yes"
else
LINE="$LINE|no"
fi
if [ -n "`grep $PATCH 9D`" ] ;then
LINE="$LINE|yes"
else
LINE="$LINE|no"
fi
if [ -n "`grep $PATCH 1A`" ] ;then
LINE="$LINE|yes"
else
LINE="$LINE|no"
fi
print $LINE
done
- Tags:
- grep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-18-2005 07:07 AM
тАО08-18-2005 07:07 AM
Re: merging lines
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-18-2005 07:10 AM
тАО08-18-2005 07:10 AM
Re: merging lines
cat 1D.out 9D.out 1A.out | sort | uniq > patchlist.out
for p in `cat patchlist.out`
do
grep -q $p 1D.out; r1=${?}
grep -q $p 9D.out; r2=${?}
grep -q $p 1A.out; r3=${?}
r1D="no";r9D="no";r1A="no"
if [ $r1 -eq 0 ]
then
r1D="yes"
fi
if [ $r2 -eq 0 ]
then
r9D="yes"
fi
if [ $r3 -eq 0 ]
then
r1A="yes"
fi
echo $p"\t"$r1D"\t"$r9D"\t"$r1A >> $RESULTSFILE
done
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-18-2005 07:11 AM
тАО08-18-2005 07:11 AM
Re: merging lines
#Script for patch check on different hosts
patch_to_check=$1
stat=$?
echo ${patch_to_check} > /tmp/${patch_to_check}
for i in 1D 9D 1A
do
swlist ${patch_to_check} @ ${i}
if [[ ${stat} -eq 0 ]]
then
echo "yes" > /tmp/${i}
else
echo "no" > /tmp/${i}
done
fi
echo "$(cat /tmp/${patch_to_check})|$(cat /tmp/1D)|$(cat /tmp/9D)|$(cat /tmp/1A)"
Not tested, but should work.
- Tags:
- swlist
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-18-2005 07:46 AM
- Tags:
- missing attachment
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-18-2005 08:25 AM
тАО08-18-2005 08:25 AM
Re: merging lines
I'm now using all your ideas to add some extra functionality.
I want to have all the hostnames in a source file.
That way I can just modify that file and create a report on a different set of servers.
I'll let you know when done and will then assign points.
If you have tips on how to adjust posted ideas to read servers from a file and then compare the patches that would be great too.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-18-2005 08:41 AM
тАО08-18-2005 08:41 AM
Re: merging lines
================================================
cat
do
done
.
================================================
cheers!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-18-2005 08:53 AM
тАО08-18-2005 08:53 AM
Re: merging lines
Another assumption here: whichever directory you are dumping these *.out files into, does not have any outher files with .out extension except the patch lists
Having said that and assuming you have such a node, from this secure management node:
-----Code Begin-----
RESULTSFILE=pick_a_filename_here
####################################
# prepare the header line
####################################
printf "PATCH\t" > $RESULTSFILE
for host in `cat myhostsfile`
do
printf "${host}\t" >> $RESULTSFILE
done
printf "\n" >> $RESULTSFILE
####################################
# collect patches lists from servers
####################################
for host in `cat myhostsfile`
do
ssh ${host} "swlist -l product | grep PH | awk {'print $1'}" > ${host}.out
done
####################################
# create the RESULTSFILE
####################################
for file in *.out
cat $file >> templist
done
sort templist|uniq > patchlist
for patch in `cat patchlist`
do
printf $patch > pline
for host in `cat myhostsfile`
do
grep -q $patch ${host}.out; r=${?}
if [ $r -eq 0 ]
then
printf "yes\t" >> pline
else
printf "no\t" >> pline
fi
done
cat pline >> $RESULTSFILE
done
-----Code End-----
This is the type of situation that I would love to have this fixed character spacing code segment insertion feature that we are supposed to have now (but seems like nobody is aware of how to use it yet) The code would have looked much cooler with indentation.
UNIX because I majored in cryptology...