- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- scripting
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
12-05-2005 04:03 AM
12-05-2005 04:03 AM
awk -F":" 'print $1'
with
typeset -l
and
cut -c1-6
When I try to run the following:
while read testuser
do
testname = $testuser | awk -F":" '{print $1}' | typeset -l | cut -c-6
echo $testname >> testoutput
done < testfile
It gives me the following error:
videv01:/home/root/rav/test# ./testscript.sh
./testscript.sh[4]: testname: not found.
./testscript.sh[4]: testname: not found.
videv01:/home/root/rav/test# ./testscript.sh[4]: testname: not found.
./testscript.sh[4]: testname: not found.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2005 04:10 AM
12-05-2005 04:10 AM
Re: scripting
typeset -l testname
testname=$(echo $testuser | awk -F":" '{print $1}' | cut -c1-6)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2005 04:11 AM
12-05-2005 04:11 AM
Re: scripting
Although you could do a substr() inside awk to get rid of the and do a tolower() as well
for better efficiency.
testname=$(echo "${testuser}" | awk -F ':' '{print tolower(substr($1,1,6))}')
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2005 04:20 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2005 05:10 AM
12-05-2005 05:10 AM
Re: scripting
You already have the answer to your question, but, as an aside -- a useful thing sometimes -- you can lowercase or uppercase all or any field by updating it within 'awk':
# echo "UPPER MADE LOWER"|awk '{$0=tolower($0);print $0}'
...changes $0 (the current line) to lowercase. Then, all subsequent references, including those to individual fields, contain lowercase letters and can be referenced/matched as such.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2005 08:08 PM
12-05-2005 08:08 PM
Re: scripting
you can use only awk to obtain your result:
echo $testuser|awk -F ":" '{print tolower(substr($1,1,6))}'|read testname
HTH,
Art
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2005 08:24 PM
12-05-2005 08:24 PM
Re: scripting
Not for points but for your interest
www.shelldorado.com
Steve Steel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2005 08:44 PM
12-05-2005 08:44 PM
Re: scripting
awk -F: '{ print tolower(substr($1,1,6)); }' testfile >> testoutput
instead all your try.
Problem is with,
testname = $testuser | awk -F":" '{print $1}' | typeset -l | cut -c-6
Change this to,
testname = $(echo $testuser | awk -F":" '{print $1}' | typeset -l | cut -c-6)
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2005 12:41 AM
12-07-2005 12:41 AM
Re: scripting
rm testoutput
rm testokusers
rm testnotokusers
while read testuser
do
typeset -l testname
testname=$(echo $testuser | awk -F":" '{print $1}' | cut -c1-6)
echo $testname >> testoutput
done < passgvts
#the above reads passgvts file and extracts the first 6 characters of the first
field from each line thus creating a testname (in lowercase)
while read testname
do
grep $testname vosalist.sorted
if
[ $? = 0 ]
then
echo $testname >> testokusers
else
echo $testname >> testnotokusers
fi
done < testoutput
#if testname is found in the vosalist then the username is sent to testokusers e
lse it is sent to testnotokusers
while read fakeuser
fullfakename=$ {echo $fullfakename | awk -F":" '{print $1}'}
do
grep $fakeuser passgvts
if
[ $? = o ]
then
echo $fullfakename >> queryusers
fi
done < testnotokusers
The first part is working fine. What I am then trying to do is, for all the entries in testnotokusers I am trying to get the grep for it the passgvts file and send out the full entry in the first (not just first 6 characters) to a file called queryusers. This is the part that is not working. Can anybody advise?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2005 03:37 AM
12-07-2005 03:37 AM
Re: scripting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2005 09:25 PM
12-08-2005 09:25 PM
Re: scripting
rm testoutput
rm testokusers
rm testnotokusers
while read testuser
do
typeset -l testname
testname=$(echo $testuser | awk -F":" '{print $1}' | cut -c1-6)
echo $testname >> testoutput
done < passgvts
#the above reads passgvts file and extracts the first 6 characters of the first
field from each line thus creating a testname (in lowercase)
while read testname
do
grep $testname vosalist.sorted
if
[ $? = 0 ]
then
echo $testname >> testokusers
else
echo $testname >> testnotokusers
fi
done < testoutput
#if testname is found in the vosalist then the username is sent to testokusers e
lse it is sent to testnotokusers
#fullfakename=$ {echo $fullfakename | awk -F":" '{print $1}'}
while read fakeuser
do
grep $fakeuser passgvts >> queryusers
done < testnotokusers
everything works fine except one thing. In a lot of the cases I have two similar usernames in passgvts file ie:
gillars
gillarst
jonesra
jonesrat
As I am matching the entries in testnotokusers, if for example in testnotokusers I have:
gillar
gillar
jonesr
jonesr
the out put in the file queryusers is double for most entries ie:
gillars
gillarst
gillars
gillarst
jonesra
jonesrat
jonesra
jonesrat
So I want to modify my script so that it only outputs the result of grep $fakeuser passgvts to queryusers if the entry does not already exist in there. How do I do this please???
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2005 11:44 PM
12-08-2005 11:44 PM
Re: scripting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2005 06:10 AM
12-10-2005 06:10 AM
Re: scripting
Hmm, you make my head spin with all those files and tweaks. Seems to me this is not all that hard a problem when using a language like perl, or the shell, if you just remember values as you see them instead of sticking them in a file.
As others indicate... if you use a tool like awk, just lett it do as many steps as it can in one go (the field select, cut, case-change)
Anyway.. back to the last part, where you want to avoid ouput twice. Here is a practicular example which 'remembers' having seen a value by incrementing an array element in perl (could use awk or shell). Only print if it was zero before the increment.
This example also reads teh file to be grepped into a memory array, and greps that.
---- test.pl ----
open (PASS,"
while (<>) {
chomp;
if (grep(/^$_$/,@pass)) {
print "$_\n" unless $seen{$_}++;
}
}
------ usage example ----
perl test.pl < testnotokusers > queryusers
hth,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2005 09:08 AM
12-10-2005 09:08 AM
Re: scripting
just a thought,
Michael
while read testuser
do
typeset -l testname
testname=$(echo $testuser | awk -F":" '{print $1}' | cut -c1-6)
echo $testname
done < passgvts | sort -u > testoutput