- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- script query
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
11-16-2005 04:21 AM
11-16-2005 04:21 AM
script query
while read fullname
do
shortname=$ echo $fullname | cut -c1-5
grep $shortname file2
if
[ $? = 0 ]
then
echo $fullname >> file3
fi
done < file1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2005 04:39 AM
11-16-2005 04:39 AM
Re: script query
shortname=$ echo $fullname | cut -c1-5
Should be this:
shortname=$(echo $fullname | cut -c1-5)
Your 'if [ $? = 0 ]' needs to all be on one line as well. I suspect it is in your script, but the Forums screwed it up when you posted it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2005 04:46 AM
11-16-2005 04:46 AM
Re: script query
try this:
while read fullname
do
shortname=$( echo $fullname | cut -c1-5)
grep -q $shortname file2
if [ $? = 0 ]
then
echo $fullname >>file3
fi
done < file1
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2005 07:42 AM
11-16-2005 07:42 AM
Re: script query
# cat file2 | while read shortname
> do
> grep "^$shortname" file1 > file3
> done
thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2005 05:30 PM
11-16-2005 05:30 PM
Re: script query
# awk '{ var=substr($1,0,6);print var; }' file1 | while read sname;
do
grep $sname file2 >> file3
done
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2005 05:36 PM
11-16-2005 05:36 PM
Re: script query
Your logic of,
# cat file2 | while read shortname
> do
> grep "^$shortname" file1 > file3
> done
is good. However with problem.
# Problem 1:
grep "^$shortname" file1 > file3
Change this to append mode as,
grep "^$shortname" file1 >> file3
# Problem 2:
grep "^$shortname" file1
It will log file1 contents to file3. We can change as,
grep -q '^$shortname" file1
[[ $? -eq 0 ]] && echo $shortname >> file3
# Problem 3:
Change cat file2 to as,
while ..
do
..
done < file
Will be more good.
# Use as,
rm -f file3
while read shortname
do
grep -q "^$shortname" file1
[[ $? -eq 0 ]] && echo "$shortname" >> file3
done < file2
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2005 09:56 PM
11-20-2005 09:56 PM
Re: script query
I tried Patrick Wallek's suggestion but no file3 was produced.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2005 10:05 PM
11-20-2005 10:05 PM
Re: script query
Muthukumar, before I use your following script:
# awk '{ var=substr($1,0,6);print var; }' file1 | while read sname;
do
grep $sname file2 >> file3
done
can you please explain what the awk line is exactly doing? I am new to scripting and have no experience of awk.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2005 10:17 PM
11-20-2005 10:17 PM
Re: script query
while read fullname
do
shortname=$(echo $fullname | cut -c1-5)
if (grep -i $shortname file2)
then
echo $shortname >> file3
fi
done < file1
I supposed you wanted to output shortname to file3 and not fullname to file3 , as these
are already in file1 right !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2005 10:25 PM
11-20-2005 10:25 PM
Re: script query
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2005 10:49 PM
11-20-2005 10:49 PM
Re: script query
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2005 11:35 PM
11-20-2005 11:35 PM
Re: script query
since none of your suggestions have produced the correct result, you should perhaps supply some authentic input material: one problem could be that a shortname, equal to the first 6 chars of a fullname, will have more than a single match in fullname, e.g.:
file_of_fullnames
Stevens, Shaking
Stevenson, Robert Louis
The shortname for both, "Steve" will have two hits - and they are a bit apart, literally speaking...
Are the shortnames unique?
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2005 05:03 AM
11-21-2005 05:03 AM
Re: script query
Have you tried my suggestion? It does exactly what you're looking for:
# cat file2 | while read shortname
> do
> grep "^$shortname" file1 >> file3
> done
This will output only matching longnames into file3.
hope it helps!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2005 07:58 PM
11-22-2005 07:58 PM
Re: script query
I see what you mean:
This will do the trick for you:
while read fullname
do
shortname=$(echo $fullname | cut -c1-5)
if (grep -i $shortname file2)
then
echo $fullname >> file3
fi
done < file1
good luck