A find and replace script


 
Thread Tools Search this Thread
Operating Systems Linux A find and replace script
# 1  
Old 06-21-2012
A find and replace script

Hello everyone,
I am trying to do a simple script (shell or perl) for a bioinformatic problem, where I want to use a list from file2 and append this information to file1 (output).

Example:
File1
Code:
>Apple1 
GAGACGATTTATATATAGAAGAGAG
>Banana2 
CAGAGAGAGAGACCCCCCCCCCCC

File2
Code:
>Apple1      20     100
>Banana2    30     300

Ouput (new File1)
Code:
>Apple1   20     100
GAGACGATTTATATATAGAAGAGAG
>Banana2  30     300
CAGAGAGAGAGACCCCCCCCCCCC


If anyone has any feedback that would be greatly appreciated.


Cheers

herasj

Last edited by Scrutinizer; 06-21-2012 at 05:49 PM.. Reason: code tags
# 2  
Old 06-21-2012
Try:
Code:
awk 'NR==FNR{A[$1]=$0; next}$1 in A{$0=A[$1]}1' file2 file1

This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 07-06-2012
Thanks, that helped!!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find and Replace in Shell script

Friends, I have more than 1000 lines in text file which needs to be converted as UPPERCASE by adding _ com.sun.url=www.sun.com com.ssl.port=808 com.ui.path=/apps/ssi Expected output com.sun.url=_COM.SUN.URL_ com.ssl.port=_COM.SSL.PORT_ com.ui.path=_COM.UI.PATH_ Thanks in... (4 Replies)
Discussion started by: baluchen
4 Replies

2. Shell Programming and Scripting

Shell script to find and replace contents of files in directory

Hi all This is my first post. Please bear with me with all my mistakes. I started learning shell since couple of days now and this might be quite basic for all, i want to search for files in a directory containing specific string and replace it with new string. The code i wrote is quite bulky... (2 Replies)
Discussion started by: theprogrammer
2 Replies

3. UNIX for Dummies Questions & Answers

Script to find line in one file and replace in another

Hey Guys, im looking for a script that will work under OSX. What i want to do is copy information from one file (Specific LIne) and write it to a certain line in another. To be more specific... I want the hostname of a mac to be gathered ( i assume its stored in a .plist file somewhere) and... (2 Replies)
Discussion started by: padgo
2 Replies

4. Shell Programming and Scripting

Have a find/replace perl script thats broke

Hello Folks, #!/usr/bin/perl use File::Find; open F,shift or die $!; my %ip=map/(\S+)\s+(\S+)/,<F>; close F; find sub{ if( -f ){ local @ARGV=($_); local $^I=""; while( <> ){ !/#/ && s/(\w+)\.fs\.rich\.us/$ip{$1}/g; print; } }... (8 Replies)
Discussion started by: richsark
8 Replies

5. Shell Programming and Scripting

Script to multiple find and replace in a single file

Dear all I need a script for multiple find and replace in a single file. For example input file is - qwe wer ert rty tyu asd sdf dgf dfg fgh qwe wer det rtyyui jhkj ert asd asd dfgd now qwe should be replace with aaaaaa asd should be replace with bbbbbbbb rty should be replace... (6 Replies)
Discussion started by: wildhorse
6 Replies

6. Shell Programming and Scripting

Help in writing a find/replace script using awk

Hi All, I need to write a script that will go through 600+ files and perform find and replace. I was going to use sed but there is a level of complexity that is doing my head in. To explain: I have 600+ files that have a line in them that reads (for example) FILE=DCLCLHST... (4 Replies)
Discussion started by: Kocko
4 Replies

7. Shell Programming and Scripting

shell script to find and replace a line using a identifier

Hi all im having trouble starting with a shell script, i hope someone here can help me i have 2 files file1: 404905.jpg 516167 404906.jpg 516168 404917.psd 516183 404947.pdf 516250 file2: 516250 /tmp/RecyclePoster18241.pdf 516167 /tmp/ReunionCardFINAL.jpg 516168... (7 Replies)
Discussion started by: kenray
7 Replies

8. Shell Programming and Scripting

shell script to find and replace string in multiple files

I used the following script cd pathname for y in `ls *`; do sed "s/ABCD/DCBA/g" $y > temp; mv temp $y; done and it worked fine for finding and replacing strings with names etc. in all files of the given path. I'm trying to replace a string which consists of path (location of file) ... (11 Replies)
Discussion started by: pharos467
11 Replies

9. Shell Programming and Scripting

Find and Replace in multiple files (Shell script)

hi guys, Suppose you have 100 files in a folder and you want to replace all occurances of a word say "ABCD" in those files with "DCBA", how would you do it ??? jatin (13 Replies)
Discussion started by: jatins_s
13 Replies

10. UNIX for Dummies Questions & Answers

improving my script (find & replace)

Hi all, I have a script that scan files, find old templet and replace it with new one. #!/bin/ksh file_name=$1 old_templet=$2 new_templet=$3 # Loop through every file like this for file in file_name do cat $file | sed "s/old_templet/new_templet/g" > $file.new #do a global searce and... (8 Replies)
Discussion started by: amir_yosha
8 Replies
Login or Register to Ask a Question