Match and copy by text


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Match and copy by text
# 1  
Old 03-06-2015
Match and copy by text

In the attached .txt file, I am trying to match $5 with $1 and copy $4 to $7.

That file was created using:

Code:
 awk 'BEGIN {OFS="\t"} {sub("chr","",$1)} {print $5,$2,$3,$1,$4,$7} {print $6,$3,$2,$1}' matrix_pxlence.txt > output.txt

but I can not seem to add this last bit to the command. Thank you Smilie.

Example output:
$5 = DTE3504500000001 and in $1 Row 1 and 2 contains that text (before ref or antiref), so $4 which is 1 is copied to $7 with the header combined.

Code:
DTE3504500000001ref	34529	35031	1	DTE3504500000001	SeqRxn4  1
DTE3504500000001antiref	35031	34529	1

Thank you Smilie.

Last edited by Scrutinizer; 03-06-2015 at 03:59 PM.. Reason: additional CODE tags
# 2  
Old 03-07-2015
Moderator's Comments:
Mod Comment I don't see how this thread has been solved, but it appears to be an old, incorrectly specified duplicate of the thread: Match partial text

This thread is closed.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Match text to lines in a file, iterate backwards until text or text substring matches, print to file

hi all, trying this using shell/bash with sed/awk/grep I have two files, one containing one column, the other containing multiple columns (comma delimited). file1.txt abc12345 def12345 ghi54321 ... file2.txt abc1,text1,texta abc,text2,textb def123,text3,textc gh,text4,textd... (6 Replies)
Discussion started by: shogun1970
6 Replies

2. Shell Programming and Scripting

Display match or no match and write a text file to a directory

The below bash connects to a site, downloads a file, searches that file based of user input - could be multiple (all that seems to work). What I am not able to figure out is how to display on the screen match found or no match found" and write a file to a directory (C:\Users\cmccabe\Desktop\wget)... (4 Replies)
Discussion started by: cmccabe
4 Replies

3. Shell Programming and Scripting

Match text and print/pipe only that text

I'm trying to pull an image source url from a html source file. I'm new with regex. I'm in BaSH. I've tried grep -E 'http.*jpg' file which highlights the text, but gives me 2 problems: 1) Results aren't stand alone and can't be piped to another command. (I believe it includes everything in... (5 Replies)
Discussion started by: amx401
5 Replies

4. UNIX for Dummies Questions & Answers

Search String, Out matched text and input text for no match.

I need to search a string for some specific text which is no big deal using grep. My problem is when the search fails to find the text. I need to add text like "na" when my search does not match. I have tried this command but it does not work when I put the command in a loop in a bash script: ... (12 Replies)
Discussion started by: jojojmac5
12 Replies

5. Shell Programming and Scripting

Match and copy

Trying to match $4 in LCH_exons.txt with $1 in refseq_genes.txt, if there is a match then the value in $4 in refseq_exons is copied to $5 of LCH_exons. For example, $4 in LCH_exons.txt is NRAS and that matches $1 row 11270 and the value in $4 is -, so the - would be copied to LCH_exons.txt in... (5 Replies)
Discussion started by: cmccabe
5 Replies

6. Shell Programming and Scripting

Match text in a range and copy value

In the files attached, I am trying to: if Files.txt $1 is in the range of Exons.txt $1, then in Files.txt $4 the value from Exons.txt $3 is copied else if no match is found Exons.txt $3 = "Intron" For example, the first value in File.txt $1 is chr1:14895-14944 and is not found in any range... (4 Replies)
Discussion started by: cmccabe
4 Replies

7. Shell Programming and Scripting

Need Help - match file name and copy to Directory

I am trying to sort the following files from folder Bag to Apple, Cat Food, Dog Food. I can get all of the files I want into a new folder, but not sure of the best approch to get them to their final directory My Files ========== apple.1234.ext apple.1235.ext cat food 101.ext Cat Food... (2 Replies)
Discussion started by: mtschroeder
2 Replies

8. UNIX for Dummies Questions & Answers

Two files; if cells match then copy over other columns

My current issue is dealing with two space delimited files. The first file has column 1 as the sample ID's, then columns 2 - n as the observations. The second file has column 1 as the sample ID's, column 2 as the mother ID's, column 3 as the father ID's, column 4 as the gender, and column 5... (3 Replies)
Discussion started by: Renyulb28
3 Replies

9. UNIX for Advanced & Expert Users

Match the string and copy records to another location

Hi, I have particular set of files which have the below contents: ****** PBX TYPE:ID6 PBX-id: A11 rolled on 123456 368763 00 >>>>>> A11,2008-07-01 21:31:00.000,42,42112, ,XXXXXXXX A11,2008-07-01 21:40:00.000,6, , ,XXXXXXX A12,2008-07-01 21:53:00.000,68, , ,XXXXXXXX... (12 Replies)
Discussion started by: bsandeep_80
12 Replies

10. Shell Programming and Scripting

Match a pattern and copy above two lines

Dear experts, i want to search pattern tre and copy this line and above two lines in a seperate file:: Thanks for the help SEV="MAJOR": RX-TX HW-FAILURE DOMAIN="alcomc2_BSS_20 unit-type % bts nbr % 24 SBL-type % tre nbr % 4 subnb % 255 BR, Danish (16 Replies)
Discussion started by: Danish Shakil
16 Replies
Login or Register to Ask a Question