Thanks every one (Danmero, Bartus11, Pravin27 (the Awk folks)!!! Kurumi (Ruby Wrangler!!) ygemici (Sed-lovers) !!...
@Danmero, although my problem is solved I am intrigued that your code doesn't work for my sample files (the files I posted first i.e. Freq.txt and Pval.txt. Just so I understand better, could you please explain the code? I had made my sample files quickly on windows notepad. I then remade them using vi editor and still I had the same problems running your code. I tried to debug myself but never figured it out. I do realize it must be something very mundane. Your code works fine for my actual files though!!
@kurumi....I have some problems running your Ruby script, but I will get back to you after I do some debugging myself
@ygemici..Your sed script also gave me some problems but again...I will get back to you after I try some tweaking myself
csn
---------- Post updated 10-04-10 at 10:52 AM ---------- Previous update was 10-03-10 at 05:03 PM ----------
Quote:
Originally Posted by cs_novice
@Danmero, although my problem is solved I am intrigued that your code doesn't work for my sample files (the files I posted first i.e. Freq.txt and Pval.txt. Just so I understand better, could you please explain the code? I had made my sample files quickly on windows notepad. I then remade them using vi editor and still I had the same problems running your code. I tried to debug myself but never figured it out. I do realize it must be something very mundane. Your code works fine for my actual files though!!
csn
I think I figured out what the awk one liner under discussion does....
We set NR = FNR i.e., the current count (ordinal number) of record of 1st input file and second input file are same. Then when we say
Quote:
{a[$4]=$5}a[$1]
we are capturing the elements of field5 (i.e., of file1, $5), provided field 4 (i.e. file1;$4) matches the first field of file 2 ($1), in an associative array a[$1] ( the 'next' does not let the program do anything else with file1).
We then print all fields in the file 2 and of course separated by a tab the associative array that contains the elements of $5 (from file 1).
Quote:
{print $0"\t"a[$1]}
Since we set NR==FNR the array only has as many lines as in file2 (I think this statement of mine is wrong but I am not sure)
Even as a biologist I am beginning to get interested in the nitty gritty of programing: I think I like it. I hope to able to do the same with the sed and ruby script, but that is for another day. Even a simple awk code has squeezed the maximum out of me. So much power packed in one little statement.
please feel free to correct my understanding of this.
have a good day
csn
Last edited by cs_novice; 10-03-2010 at 07:15 PM..
You got most of it right, except the "NR==FNR" part. It is not setting any of these variables. Instead it is comparing them, which is true only when processing 1st file (as FNR gets reset to 1 with each file). This allows us to build associative array "a" based on contents of the 1st file, and then use it to compare values with the 2nd file.
You got most of it right, except the "NR==FNR" part. It is not setting any of these variables. Instead it is comparing them, which is true only when processing 1st file (as FNR gets reset to 1 with each file). This allows us to build associative array "a" based on contents of the 1st file, and then use it to compare values with the 2nd file.
Thanks...I now understand this a lot better!! These are all logic statements...it is either true or false!!
will keep updating as I get better at this.
csn
a bug(?) in the awk one liner for column comparison
Hello Friends
I have been using this awk one liner
to compare field 4 of the file Gene_Count.txt to field 1 of Pval.txt and extract field 5 of Gene_Count.txt and print it along side all columns of Pval.txt.
I know that I have already discussed quite a bit about the files, however for sake of completeness I have included the slightly modified files to illustrate the problem.
Gene_Count.txt
Pval.txt (note this now also includes the ID that has a zero count (in field 5 of Gene_count)
on using the awk command given above I get this out put:
Pval_count
This is great until I noticed that row #2 of Gene_count whose $5 (Field5) is '0' is thrown out:
I have noticed that all records where the field 5 of 'Gene_Count.txt' is '0' is thrown out although this seems to defy logic (at least as far as I understand). I need the records even if the field 5 value is '0'.
I'm writing a script for searching substring in file content and then moving found files. So far I've wrote script shown below
grep -lir 'stringtofind' $1 | xargs mv -t $2
How can i count number of files moved? (4 Replies)
Hi,
I wanted to check whether the x,y,z coordinates of two files are equal or not. At times, when one file is converted to another suitable file extension , there are some chances that the data mismatch would happen during the conversion. In order to avoid the data misfit, i would like to... (6 Replies)
Hi ULF,
Good day! I'm working on a LINUX Suse server and I have an entry in CRON which looks like this below:
0 5 * * * /usr/bin/find /opt/nsfw/var/partition-all/ -name "RCV_SASN*" -exec mv '{}' /opt/nsfw/var/rcv-archive/ \;
This tool runs everyday at 5am and it will just move the files... (7 Replies)
Hi,
Can any one help with my below requirement.
i need to compare each line by line and in each line i have to compare some columns values with previous line column values in perl script.
Can any one help me........! its very urgent.
Thanks (3 Replies)
Hi.
I am actually doing all of this on OSX, but using unix apps and script.
I have built my own transparent rsync/open directory/mobility/etc set of scripts for the firm I work at, and it is all almost complete except for ONE THING.
I have the classic problem with rsync where if a user... (0 Replies)
Hi,
I want to know the user ID who moved a file from one directory to another Directory.
Example: File1 created by user A is present in dirA
then some one has moved it to dirB using "mv" command
I want to know the user ID who moved the file to dirB.
As far as i know "ls -lrt" command... (1 Reply)
Hi everyone,
In a directory I have files with various extensions. I would like to move all the files ending in .L2 into a directory: ~/test. But I would also like to show which files are being moved. Of course I could type:
$ ls *.L2
$ mv *.L2 ~/test
Is there a way I can combine these two... (5 Replies)
Hello,
I am using rsync to make sure that my folder "local" mirrors the remote directory "remote". When a file is copied from "remote" to "local", I need to apply a bash script to it. What would be a neat way to do that?
Thanks
ps: is there a way to edit the title of the thread (I am a bit... (5 Replies)
I'm moving a list of files of some extension and I wish to output the moved filenames into a text file, I tried using the command below, but after all the files are moved, I got a blank file.
find /abc/temp -type f -mtime +365 \( -name "*.bak" -o -name "*.log" \) -exec mv -f {} /junk \; >>... (3 Replies)