Sorting the Void File in CSH


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sorting the Void File in CSH
# 1  
Old 10-29-2005
Sorting the Void File in CSH

First and foremost, this is not a homework for your information. I'm just new to using c-shell programming and I just wanted to make my life easier @ work.

Say, the file contains the following:
Code:
ID        FILE NO.        SL      VP
1           1             22      33
1           2             22      33          
2           3             33      44
3           4             33      55
4           5             44      55
4           6             44      55
4           7             44      55
3           8             33      55
5           9             77      88

In the above example,
The First, Third and Fourth Fields of Rows (1 & 2) are repeated and so with Rows (4 & 8) and Rows (5, 6 & 7).

I want my csh script to check for void File No. If the first, second and third fields are repeated, the former shows me the void file/s. In this example, File Nos. 1, 4, 5 and 6 are void. File 2 is the good file and so with File 7 & 8. Files 3 & 9 are good files as well since they are not repeated.

Thanks in Advance.

Last edited by Perderabo; 11-03-2005 at 05:42 PM.. Reason: add code tags for readability
# 2  
Old 11-03-2005
From the above example, I was able to extract the rows that are not repeated on the line.

awk '{print substr($0,6,5)}' $SOLHOME/internalDisk/2 | sort -k1,2 | uniq -d
Result:
22 33
33 55
44 55

How do I compare this result now from the original file to show me the FILE NO. of the repeated rows except the last line of these rows?
# 3  
Old 11-06-2005
Hello Gentlemen!

I'm new to Csh script programming and I have not really attended any formal unix training course whatsoever. I'd really been trying hard to solve the above example but to no avail. I tried using "foreach" but I'm not really sure how this command works. I've read the man foreach but it didn't give much help either. Could someone please give me an input?

Thanks a lot....
# 4  
Old 11-07-2005
I can't recommend using csh for shell programming. See this article: Csh Programming Considered Harmful.

Your problem can be solved using awk....
Code:
awk '{a[$1,$3,$4]++;b[$1,$3,$4]=$0}END{for(x in a)if(a[x]==1)print b[x]}' file

....which gives...
Code:
ID        FILE NO.        SL      VP
5           9             77      88
2           3             33      44

See Arrays in awk for details.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

Malloc to void pointer fails

I have a function to which I will pass a struct ID and it will return me a string. I will pass a pointer to store the name string and that pointer will be allocated memory by the function called. int ConvertIDToName(void *id, void *name, size_t *size) { int status = 0; ... (5 Replies)
Discussion started by: rupeshkp728
5 Replies

2. Programming

Parameter passing to function with void * as Argument

Earlier I had one structure C typedef struct c { int cc; }CS; I used to call a library function say int GetData(CS *x) which was returning me the above structure C with data. GetData(CS *x) Function call used to be like: CS CSobj; GetData(&CSObj); Now there are two... (12 Replies)
Discussion started by: rupeshkp728
12 Replies

3. Programming

void pointer

hi guys! Is there such a thing as double void pointer dynamic allocation? And if so is it something like this? int n; void** a; a=malloc(n*sizeof(void*)); (12 Replies)
Discussion started by: vlm
12 Replies

4. Shell Programming and Scripting

Eliminate double void line

Hi, I need to eliminate each second void line in a text file. novus MILLENNIO ineo frater in episcopatus , presbyter et diacon|diaconus , (1 Reply)
Discussion started by: mjomba
1 Replies

5. Programming

functions that manipulate void pointers

I have two or more linked lists that have the same names for their "next". For example, struct server_t { sockaddr_in * sin; server_t * next_; } struct player_t { char name; player_t * next_; } How can I get a function to take in either type and manipulate the pointers? I... (3 Replies)
Discussion started by: pyramation
3 Replies

6. UNIX for Dummies Questions & Answers

void (char *asd)

void asdf(char *asd) is this thing a pointer? (1 Reply)
Discussion started by: khestoi
1 Replies

7. Shell Programming and Scripting

csh failing to call an 2 embedded csh script

I have an extraordinary problem with a csh script.....(feel free to berate the use of this but I'm modifying an existing bunch of them) Anyway, I have a master csh script which in turn calls a second csh script. This second csh script is below. Within this second script are two compiled C++... (1 Reply)
Discussion started by: pollsizer
1 Replies

8. Programming

What is the difference between f(...), f(void) and f()

What is the difference between f(...) , f(void),f() I know that f(void) doesn't take any parameters, but what about f() and f(...) Does the last call of function even exists? (2 Replies)
Discussion started by: purplelightspar
2 Replies

9. Programming

How to return void function pointer

Hello all im trying to build function that will return void function pointer what is mean is ( not working ) the main function void * myClass::getFunction(int type){ if(type==1) return &myClass::Test1; if(type==2) return &myClass::Test2; } void myClass::Test1(){... (1 Reply)
Discussion started by: umen
1 Replies
Login or Register to Ask a Question