analyzing data from more than one file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting analyzing data from more than one file
# 8  
Old 01-25-2009
Quote:
Originally Posted by shira
When you want to study a language to its depth, you have to have strong basic skills and then you can use the shortcuts. Like when I studied ansi c, I didn't use all the <string.h> functions, I wrote them by myself.
And as you can see, I cannot solve this particular problem, so I have to learn this in order to progress.

In csh, there may be no solution. Progress is moving to a real scripting language.
Quote:
Also, cshell is a basic script language.

No, it's not. It is a half-baked scripting language, and it is not used for serious scripting. It is not even required to be present on a UNIX system.

In a POSIX shell, your problem is trivial.
Quote:
I will move on to more advanced languages when I feel I have enough knowledge.

You have all the knowledge you need. Move on.
# 9  
Old 01-25-2009
Wow, Bill Joy is not very popular in here, heh?
Thanks for believing in me, but you've made me even more anxious to find out the answer (though I will move on, I promise).
# 10  
Old 01-25-2009
Quote:
Originally Posted by shira
Wow, Bill Joy is not very popular in here, heh?

No one has said anything against Bill Joy; when it was written csh was an improvement for interactive use, but not for scripting.
Quote:

Thanks for believing in me, but you've made me even more anxious to find out the answer

What makes you think there is an answer in csh. Some things simply cannot be done in csh.

Have you read this article? Escpecially note item no. 5!
Top Ten Reasons not to use the C shell
# 11  
Old 01-25-2009
I've read all the articles that have anything to do with c shell.
And they don't say that there isn't any solution, they say that there is a solution, but it's messy, long and ugly.

But I have the solution to my problem, and I'll write it down for all the future head-breakers. It is so simple, and I can't believe I didn't think about it myself (McCartney says it better - "With a little help from my friends"):

When you want to compare a word from a column in one file to a word from another column in another file, you simply do this (for any i, j you choose):

Code:
set list1 = `cut -d" " -fi ${1}`
set list2 = `cut -d" " -fj ${2}`
#We simply "crop" all the words in field i (in the first file) into a list called list1,
#and the same for the second file. Notice the back quotes!

So what was my head-on-the-wall-banging about?
Well, I thought about doing that, but since there isn't any single-charactered showcase for enter (\n) (for what I know of), I didn't think it would work. So what's the trick? The cut command, by definition, goes through each line until it reaches the end of the file, so out of each line it only takes the word in your chosen field and puts it in the list by order.

If there's anyone who wants to read the full program, you're welcome to leave me messages with your e-mail.

What's the lesson? Always check your ideas before eliminating them. Smilie

Last edited by shira; 01-25-2009 at 01:15 PM..
# 12  
Old 01-25-2009
Simply with awk:

Code:
awk 'NR==FNR{a[$1];next} $2 in a' file1 file2

Regards
# 13  
Old 01-25-2009
Quote:
Originally Posted by shira
I've read all the articles that have anything to do with c shell.

<chow-chow>

When you want to compare a word from a column in one file to a word from another column in another file, you simply do this (for any i, j you choose):

Code:
set list1 = `cut -d" " -fi ${1}`
set list2 = `cut -d" " -fj ${2}`
#We simply "crop" all the words in field i (in the first file) into a list called list1,
#and the same for the second file. Notice the back quotes!

<chop-chop>
After all - this ain't a csh 'solution' - it's a 'cut' solution which could have been achieved with sed/awk/... in the same manner.
# 14  
Old 01-25-2009
All of you are right.
But I needed a solution which doesn't contain sed or awk.
Thanks for the responses, though.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Lex: analyzing a C file and printing out identifiers and line numbers they're found on

Florida State University, Tallahassee, FL USA, Dr. Whalley, COP4342 1. The problem statement, all variables and given/known data: Create a lex specification file that reads a C source program that ignores keywords and collects all identifiers (regular variable names) and also displays the line... (3 Replies)
Discussion started by: D2K
3 Replies

2. Programming

Difficult in analyzing an algorithm

Hello, I was reading Heuritics text and came across an algorithm below. Finding hard to analyze it can any one help me out below... How to analyze if I take say no. of types are 5 and each type has say 20 coins. thanks. Let {c1, c2...cn=1} be a set of distinct coin types where ci is... (1 Reply)
Discussion started by: sureshcisco
1 Replies

3. AIX

Analyzing CPU usage

Hi Admins, I need your help to analyze the cpu usage of our main server. I have shared below, CPU usages during busy hours and non busy hours. CPU usage is always full at busy hours. Users always complaints about slowness. This server is a lpar partition and configured as uncapped mode. ... (7 Replies)
Discussion started by: newaix
7 Replies

4. UNIX for Dummies Questions & Answers

analyzing list with street addresses

Hi List, Could someone please point me into the right direction with the following: I have a file containing a list of street addresses. I need to sort all the street addresses with the same number to a new file containing the street name and corresponding number. So: Strawinskylaan... (3 Replies)
Discussion started by: M474746
3 Replies

5. UNIX and Linux Applications

Benchmarking and performance analyzing in OS

Is/Are there an/some application/applications , package/packages for benchmarking or system performance measuring which are there for almost all Linux releases and distributions? (2 Replies)
Discussion started by: nixhead
2 Replies

6. Emergency UNIX and Linux Support

Analyzing Core Dump

We have a binary that generates coredump. So I ran the gdb command to analyze the issue. Pleae note the binary and code are in two different locations and we cannot build the whole binary using debugging symbols. Hence how and what details can I find from below backtarce: gdb binary corefile ... (5 Replies)
Discussion started by: uunniixx
5 Replies

7. AIX

Help required in analyzing errpt in aix 5.3

I have received errpt like this.Any help will be highly appreciated.Recently my application has been migrated to aix 5.3 and working fine in aix 5.2 with out crashes. LABEL: CORE_DUMP IDENTIFIER: C69F5C9B Date/Time: Thu Apr 23 09:41:29 EDT 2009 Sequence Number: 948... (3 Replies)
Discussion started by: kittu1979
3 Replies

8. Shell Programming and Scripting

analyzing tcpdump output

hello, i have a lot of pcap files (tcpdump output) that i want to compare. every tcpdump output has two file, server and client. what i want to do is: 1. take timestamp, source address, destination address, and packet id from each file (server and client) 2. find the packets sent from... (0 Replies)
Discussion started by: slumpia
0 Replies

9. UNIX for Advanced & Expert Users

Analyzing System Core Files?

can some tell me how to do this. I mean, i tried finding this out on my own but when I checked the man pages, i got a truckload of commands available pertaining to this task which in turn got me confused. so my question is, if there is a simple straight forward(not necessarily easy) way to... (2 Replies)
Discussion started by: TRUEST
2 Replies
Login or Register to Ask a Question