(Perl or Unix) Script to get values from two files?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting (Perl or Unix) Script to get values from two files?
# 1  
Old 02-22-2012
(Perl or Unix) Script to get values from two files?

Hello,

I am working on a script to get values from 2 files, and write to a new result file.

File 1: 8-columned file separated by space:
Code:
SerialNumber-Abc123 ID-1234:0 Name-xxx Class-yyy Object-zzz Source-aaa Value-bbb Comments-ccc
SerialNumber-Abc124 ID-1234:1 Name-xxx Class-yyy Object-zzz Source-aaa Value-bbb Comments-ccc
SerialNumber-Abc125 ID-1234:2 Name-xxx Class-yyy Object-zzz Source-aaa Value-bbb Comments-ccc
SerialNumber-Abc126 ID-1234:3 Name-xxx Class-yyy Object-zzz Source-aaa Value-bbb Comments-ccc
....
...
..
.

File 2: Fasta File:
Code:
>1234:0 blah blah blah blah
gctagcatcgatcgatcagctagcgagcgactagctagctagtcgatgctgcagcatgctagctagtcgatgcatcgtagcgatgctgatcgagtcgatgcta
>1234:1 blah blah blah blah
catcgatcgatcagctagcgagcgactagctagctagtcgatgctgaaaaacagcatg
>1234:2 blah blah blah blah
tttagcagctagagctagctagtcgatgctgcagcatgctagctagtc
>1234:3 blah blah blah blah
gctagcatcgatcgatcagctagcgagcgactagctagctagtcgattttaaaggctacgtagctagctcgatcgatcgatgagaggggggagtgcta
...
..
.


I want my output to be like this:
Code:
>1234:0 | SerialNumber-Abc123 ID-1234:0 Name-xxx Class-yyy Object-zzz Source-aaa Value-bbb Comments-ccc
gctagcatcgatcgatcagctagcgagcgactagctagctagtcgatgctgcagcatgctagctagtcgatgcatcgtagcgatgctgatcgagtcgatgcta
>1234:1 | SerialNumber-Abc124 ID-1234:1 Name-xxx Class-yyy Object-zzz Source-aaa Value-bbb Comments-ccc
catcgatcgatcagctagcgagcgactagctagctagtcgatgctgaaaaacagcatg
>1234:2 | SerialNumber-Abc125 ID-1234:2 Name-xxx Class-yyy Object-zzz Source-aaa Value-bbb Comments-ccc
tttagcagctagagctagctagtcgatgctgcagcatgctagctagtc
>1234:3 | SerialNumber-Abc126 ID-1234:3 Name-xxx Class-yyy Object-zzz Source-aaa Value-bbb Comments-ccc
gctagcatcgatcgatcagctagcgagcgactagctagctagtcgattttaaaggctacgtagctagctcgatcgatcgatgagaggggggagtgcta
...
..
.


Thanks!

Last edited by ad23; 02-22-2012 at 02:36 PM..
# 2  
Old 02-22-2012
Try:
Code:
awk 'NR==FNR{id=$2;sub("ID-","",id);a[id]=$0;next}/^>/{id=$1;sub(">","",id);$0=$1" | "a[id]}1' file1 file2

This User Gave Thanks to bartus11 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get multiple values from an xml file using one of the following commands or together awk/perl/script

Hello, I have a requirement to extract the value from multiple xml node and print out the values to new file to compare. Would be done using either awk/perl or some unix script. For example sample input file: ..... ..... <factories xmi:type="resources.jdbc:DataSource"... (2 Replies)
Discussion started by: slbmind
2 Replies

2. Shell Programming and Scripting

UNIX script to interchange column values

Hi, I have the below script which is fetching the data from a file as below: awk -F "~" 'NR>1 {print $5}' 1.txt The o/p is like: 1452350 1458638 1452350 2 5696837 No i want to put 5696837 before 1458638 in above o/p So final o/p should look like: 1452350 5696837 1458638 (2 Replies)
Discussion started by: Vivekit82
2 Replies

3. Shell Programming and Scripting

Query the table and return values to shell script and search result values from another files.

Hi, I need a shell script, which would search the result values from another files. 1)execute " select column1 from table_name" query on the table. 2)Based on the result, need to be grep from .wft files. could please explain about this.Below is the way i am using. #!/bin/sh... (4 Replies)
Discussion started by: Rami Reddy
4 Replies

4. Shell Programming and Scripting

Passing PERL var values to SH Shell Script

Greetings all, If I have a SH script that calls a PERL script in the following way: perl $HOME/scripts/config.properties And in the config.properties PERL file, this Perl script only sets a number of environmental parameters in the following way: #!/usr/bin/perl $VAR1 = ( ... (3 Replies)
Discussion started by: gikyo12
3 Replies

5. Shell Programming and Scripting

Joining multiple files based on one column with different and similar values (shell or perl)

Hi, I have nine files looking similar to file1 & file2 below. File1: 1 ABCA1 1 ABCC8 1 ABR:N 1 ACACB 1 ACAP2 1 ACOT1 1 ACSBG 1 ACTR1 1 ACTRT 1 ADAMT 1 AEN:N 1 AKAP1File2: 1 A4GAL 1 ACTBL 1 ACTL7 (4 Replies)
Discussion started by: seqbiologist
4 Replies

6. Shell Programming and Scripting

perl/unix: script in command line works but not in perl

so in unix this command works works and shows me a list of directories find . -name \*.xls -exec dirname {} \; | sort -u | > list.txt but when i try running a perl script to run this command my $query = 'find . -name \*.xls -exec dirname {} \; | sort -u | > list.txt';... (2 Replies)
Discussion started by: kpddong
2 Replies

7. Shell Programming and Scripting

Perl script to change values in datafiles

Hi all, Let say I have 2 files, 1 is source file and another is destination file. Source file contains the following : Kitten Dogs Donkey Chicken Turkey And destination file contains : Kitten, 0 Dogs, 0 Donkey, 0 Chicken, 0 Turkey, 0 Kitten, 0 Dogs, 0 Donkey, 0 (16 Replies)
Discussion started by: luna_soleil
16 Replies

8. Shell Programming and Scripting

PERL - Selecting specific files based on 'date stamp' values

Hi, I've list of files in a directory, which have date stamp value in their names. ex: abc_data_20071102.csv, abc_data_20091221.csv, abc_data_20100110.csv, abc_data_20100222.csv, abc_data_20080620.csv,... etc., I need to select and process only files, within the given date... (4 Replies)
Discussion started by: ganapati
4 Replies

9. Shell Programming and Scripting

perl script to print to values in rows and columns

Hi guys I want to print the values by using this script but its giving the no of rows and columns as input instead of values Would you plz help me on this FILE- chr1.txt 1981 1 1971 1 1961 1 1941 1 perl script #!/usr/bin/perl -w $infile1 = 'chr1.txt'; $outfile3 = 'out3.txt'; ... (3 Replies)
Discussion started by: nogu0001
3 Replies

10. Shell Programming and Scripting

Values of value($$X) in unix shell script

Values of value of x ($$X) in unix shell script program ---------------- #!/bin/ksh t1='/CPI/nodeA/stubs/Test/T1' t2='/CPI/nodeA/stubs/Test/T2' cd $$1--> Parameter may me t1 or t2 ------------------- expecting cd $t1 shold go to the path but it is giving error. (5 Replies)
Discussion started by: ganesh_111
5 Replies
Login or Register to Ask a Question