- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- UNIX scripting & Storage methods
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-18-2002 02:41 AM
11-18-2002 02:41 AM
I am trying to store the occurence of a particular field in a file into something like a vector. I want to store each distinct occurence of the value, and then search the vector to do a count of the number of entries.
for example, I have a load of files that have entries like the following :
|header file|
|1|a|b|c|d|
|1|a|b|c|
|2|a|b|c|d|e|
|1|a|b|
|footer|2|
where the value "2" in the footer file is the distinct number of 'numeric types' that exist in the first pipe delimited field of each row. So if the file was as follows :
|header file|
|1|a|b|c|d|
|2|a|b|c|
|3|a|b|c|d|e|
|1|a|b|
|footer|3|
The footer shows 3 types (hope this makes sense).
what I would like to do is store each numeric type and then, as I progress through the file rows, increment a count each time a new distinct value occurs. I will need this value to stick in a file at the end of the file traversal.
I am not too familiar with UNIX scripting as I am a java programmer (and hence very familiar with vectors, etc), so I don't even know whether vectors exist in posix shell scripting.
thanks in advance people
John
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2002 02:55 AM
11-18-2002 02:55 AM
Re: UNIX scripting & Storage methods
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2002 03:39 AM
11-18-2002 03:39 AM
Re: UNIX scripting & Storage methods
Thanks for the reply, I am not too concerned with what the output would be like, just obtaining the value and being able to create this temporary storage area containing distinct values that I can count would be ideal. If it helps, just writing to any file with the distinct number count would be useful.
What I will do for the end result, is overwrite an erroneous value ie.
the wrong file footer (Only two distinct value (1 & 2) but the footer says 3):
|header|
|1|a|b
|1|a|
|2|a|b|c|d|
|footer|3|
would be overwritten using awk, to :
|header|
|1|a|b
|1|a|
|2|a|b|c|d|
|footer|2|
Which, I can manage OK
thanks again
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2002 04:18 AM
11-18-2002 04:18 AM
Re: UNIX scripting & Storage methods
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2002 04:29 AM
11-18-2002 04:29 AM
Re: UNIX scripting & Storage methods
Could you give me an example of how awk does this.
I have not done it in Java because the function I am trying to create is a smaller part of a much bigger script that uses a korn script. I am just trying to keep things simple and neat.
thanks again
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2002 04:51 AM
11-18-2002 04:51 AM
SolutionTry this script :
cat file | awk -F'|' '
/^|header\|$/{
getline
getline
nb=0
max=0
while ($2 != "footer")
{
if (a[$2] != 1)
{
a[$2]=1
nb++
if (nb > max)
max=nb
}
getline
}
printf("|footer|%d|\n", nb)
for (i=0;i<=max;i++)
a[i]=0
}'
If input file is :
|header|
|1|a|b
|1|a|
|2|a|b|c|d|
|footer|3|
|header|
|1|a|b
|3|a|
|2|a|b|c|d|
|footer|3|
Output file will be :
|header|
|1|a|b
|1|a|
|2|a|b|c|d|
|footer|2|
|header|
|1|a|b
|3|a|
|2|a|b|c|d|
|footer|3|