Operating System - Linux
1753562
Members
5954
Online
108796
Solutions
Forums
Categories
Company
Local Language
юдл
back
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
юдл
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- 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-15-2006 02:05 AM
тАО11-15-2006 02:05 AM
C++ help
Hello All,
Below is a file with the following entry.
and i want to delete following entry from file
Order of records is the file remain same.
if i give input Owner and passwd2
it should delete from this file.
Owner:Group:user:passwd
Owner:Group:user:passwd1
Owner:Group:user:passwd2
Owner:Group:user:passwd3
Owner1:Group:user:passwd
Owner2:Group:user:passwd1
Owner3:Group:user:passwd2
Owner4:Group:user:passwd3
final output
Owner:Group:user:passwd
Owner:Group:user:passwd1
Owner:Group:user:passwd3
Owner1:Group:user:passwd
Owner2:Group:user:passwd1
Owner3:Group:user:passwd2
Owner4:Group:user:passwd3
Can somone suggest me by using map ? or any
other data structure.Well i am against
using tempfile.
regards
robert
Below is a file with the following entry.
and i want to delete following entry from file
Order of records is the file remain same.
if i give input Owner and passwd2
it should delete from this file.
Owner:Group:user:passwd
Owner:Group:user:passwd1
Owner:Group:user:passwd2
Owner:Group:user:passwd3
Owner1:Group:user:passwd
Owner2:Group:user:passwd1
Owner3:Group:user:passwd2
Owner4:Group:user:passwd3
final output
Owner:Group:user:passwd
Owner:Group:user:passwd1
Owner:Group:user:passwd3
Owner1:Group:user:passwd
Owner2:Group:user:passwd1
Owner3:Group:user:passwd2
Owner4:Group:user:passwd3
Can somone suggest me by using map ? or any
other data structure.Well i am against
using tempfile.
regards
robert
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-15-2006 02:55 AM
тАО11-15-2006 02:55 AM
Re: C++ help
Robert,
I'd read the file, strtok the entries into a malloc, after checking for the first and last fields against the parameters.
At the end of the file, rewind and output the array.
Also seems you have not updated your earlier thread:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1074999
I'd read the file, strtok the entries into a malloc, after checking for the first and last fields against the parameters.
At the end of the file, rewind and output the array.
Also seems you have not updated your earlier thread:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1074999
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-15-2006 09:26 AM
тАО11-15-2006 09:26 AM
Re: C++ help
Peter suggests using strtok but you need to make a copy.
Actually there is no need to malloc, you can just filter out each record as you read and then write a new file. Unless this was excluded by Robert saying "against using tempfile".
Actually there is no need to malloc, you can just filter out each record as you read and then write a new file. Unless this was excluded by Robert saying "against using tempfile".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-15-2006 09:40 AM
тАО11-15-2006 09:40 AM
Re: C++ help
Hi,
this solution with awk
awk -v o=Owner pw=passwd2 -F: 'NF==4 && !($1==o && $4==pw)' this_file
'transform' to C. I don't think C++ specific stuff will bring any advantage.
awk -> read file line by line
-v o=Owner -> char *o, *pw;
-F: -> field = strtok(line,":");
while (strtok(NULL,":")
mfG Peter
this solution with awk
awk -v o=Owner pw=passwd2 -F: 'NF==4 && !($1==o && $4==pw)' this_file
'transform' to C. I don't think C++ specific stuff will bring any advantage.
awk -> read file line by line
-v o=Owner -> char *o, *pw;
-F: -> field = strtok(line,":");
while (strtok(NULL,":")
mfG Peter
The Universe is a pretty big place,
it's bigger than anything anyone has ever dreamed of before.
So if it's just us, seems like an awful waste of space, right?
Jodie Foster in "Contact"
- Tags:
- awk
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP