The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
What is the difference between f(...), f(void) and f() purplelightspar High Level Programming 2 04-29-2008 09:34 AM
regarding file sorting phani_sree High Level Programming 1 02-02-2007 12:04 PM
Sorting a file Khoomfire Shell Programming and Scripting 2 12-13-2005 04:48 AM
Help sorting file. gio123bg Shell Programming and Scripting 3 12-10-2003 07:15 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 10-29-2005
Registered User
 

Join Date: May 2005
Posts: 64
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 02:42 PM. Reason: add code tags for readability
Reply With Quote
Forum Sponsor
  #2  
Old 11-03-2005
Registered User
 

Join Date: May 2005
Posts: 64
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?
Reply With Quote
  #3  
Old 11-06-2005
Registered User
 

Join Date: May 2005
Posts: 64
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....
Reply With Quote
  #4  
Old 11-06-2005
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,249
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.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:40 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0