Sponsored Content
Top Forums Shell Programming and Scripting Remove or rename based on contents of file Post 302943653 by cmccabe on Monday 11th of May 2015 01:20:55 PM
Old 05-11-2015
I hope this is more clear:
I am trying to use the two files shown below to either remove or rename contents in one of those files. If in combine.txt $5 matches $5 of output.txt and the value in $1 of combine.txt is not "No Match" then that value is substituted for all values in $5 and $1 of output.txt. If however in $1 of combine.txt the value is "No Match", then the row in output.txt with that $5 value in it and the one below it are removed. Thank you Smilie.

For example,
"DTE3504500000004" is the value of $5 in combine.txt and that matches row 3 of output.txt $5 , since the value in $1 of combine.txt is "No Match", rows 9 and 10 are removed from output.txt.

"DTE3504500000005" is the value of $5 in combine.txt and that matches row 11 of output.txt $5 , since the value in $1 of combine.txt is not "No Match", rather "PXL-A0000005" that new value is used to replace all occurrences of the old value in output.txt.

Code:
file1.txt
No Match    chr1    35696    36106    DTE3504500000004
PXL-A0000005    chr1    69066    69311    DTE3504500000005

Code:
Initial output.txt:
RefPrimer    ref    antiref    omosome    PrimerSet    SeqRxn
AntirefPrimer    antiref    ref    omosome        
DTE3504500000001ref    34529    35031    1    DTE3504500000001    SeqRxn4
DTE3504500000001antiref    35031    34529    1        
DTE3504500000002ref    35032    35283    1    DTE3504500000002    SeqRxn4
DTE3504500000002antiref    35283    35032    1        
DTE3504500000003ref    35284    35506    1    DTE3504500000003    SeqRxn4
DTE3504500000003antiref    35506    35284    1        
DTE3504500000004ref    35696    36106    1    DTE3504500000004    SeqRxn4
DTE3504500000004antiref    36106    35696    1        
DTE3504500000005ref    69066    69311    1    DTE3504500000005    SeqRxn4
DTE3504500000005antiref    69311    69066    1

Code:
Desired output.txt:
RefPrimer    ref    antiref    omosome    PrimerSet    SeqRxn
AntirefPrimer    antiref    ref    omosome        
DTE3504500000001ref    34529    35031    1    DTE3504500000001    SeqRxn4
DTE3504500000001antiref    35031    34529    1        
DTE3504500000002ref    35032    35283    1    DTE3504500000002    SeqRxn4
DTE3504500000002antiref    35283    35032    1        
DTE3504500000003ref    35284    35506    1    DTE3504500000003    SeqRxn4
DTE3504500000003antiref    35506    35284    1        
PXL-A0000005ref    69066    69311    1    PXL-A0000005    SeqRxn4
PXL-A0000005antiref    69311    69066    1


Last edited by cmccabe; 05-11-2015 at 03:09 PM..
 

9 More Discussions You Might Find Interesting

1. Solaris

remove the contents of a file

Hi Let say a flat file contains 1000 lines. The cursor is at the 530 line number. Now I like to delete all the line at one ahot. how it can be done? (2 Replies)
Discussion started by: surjyap
2 Replies

2. Shell Programming and Scripting

Read File and use contents to rename another

Hello guys, thank God that I found this forum. I hope that someone can help me because I don't have any idea on how to start it. I know that for some of you this is a very simple task but I'm not as advance on shell scripting like many people out there. I got this file with a permanent... (10 Replies)
Discussion started by: Shark Tek
10 Replies

3. Shell Programming and Scripting

Remove lines based on contents of another file

So, this issue is driving me nuts! I was hoping to get a lending hand here... I have 2 files: file1.txt contains: this is example1 this is example2 this is example3 this is example4 this is example5 file2.txt contains: example3 example5 Basically, I need a script or command to... (4 Replies)
Discussion started by: bashshadow1979
4 Replies

4. Shell Programming and Scripting

Remove all digits and rename a file

Hi, I have a file nexus-1234 in a directory. I want to generate a random number and replace the 1234 with it and rename the file. So nexus-1234 becomes nexus-2863 after running the script. Any help is appreciated. Thanks in advance. (2 Replies)
Discussion started by: scorpioraghu
2 Replies

5. Shell Programming and Scripting

File comparison based on contents

Hi I have 2 files 1.del ---- 1,2,3,4,5 1,2,3,4,4 1,1,1,1,2 2.del ---- 1,2,3,4,5 1, 1,2,3,4,4 1,1,1,1,2 I need to compare the above two files in unix, as in the output should only tell the difference in contents as I should get only the line 1 ( from 2.del) , rest all lines are... (4 Replies)
Discussion started by: Ethen561
4 Replies

6. Shell Programming and Scripting

How to remove a line based on contents of the first column?

Good day all. Using basic UNIX/Linux tools, how would you delete a line based on a character found in column 1? For example, if the CITY name contains an 'a' or 'A', delete the line: New York City; New York Los Angeles; California Chicago; Illinois Houston; Texas Philadelphia;... (3 Replies)
Discussion started by: BRH
3 Replies

7. Shell Programming and Scripting

How to read contents in each file and rename the file?

Hello All, Can you help me in writing a script for reading the specific position data in a file and if that data found in that file that particular file should be renamed. Ex: Folder : C:\\test and Filename : CLSACK_112214.txt,CLSACK_112314.txt,CLSACK_112414.txt Contents in the file would... (3 Replies)
Discussion started by: nanduedi
3 Replies

8. Shell Programming and Scripting

How to remove contents from file which are under bracket?

hello Friend, In hostgroup file, i have define lots of hostgroups. I need to remove few of them without manually editing file. Need script or syntax. I want to search particular on hostgroup_members and delete hostgoup defination of it. for example. define hostgroup{ hostgroup_name... (8 Replies)
Discussion started by: ghpradeep
8 Replies

9. UNIX for Beginners Questions & Answers

Rename file in directory using contents within each file

In the below there are two generic .vcf files (genome.S1.vcf and genome.S2.vcf) in a directory. There wont always be two genaric files but I am trying to use bash to rename each of these generic files with specfic text (unique identifier) within in each .vcf. The text will always be different, but... (11 Replies)
Discussion started by: cmccabe
11 Replies
RDUP-UP(1)							       rdup								RDUP-UP(1)

NAME
rdup-up - update a directory tree with a rdup archive SYNOPSIS
rdup-up [OPTION]... DIRECTORY DESCRIPTION
With rdup-up you can update an (possibly) existing directory structure with a rdup archive. The rdup archive has to be given to rdup-up's standard input. Username and uids rdup outputs both the username and uid, the receiving system (which may be a totally different system) checks if the username and uid match. If the username and uid don't match the (numeric) uid is used on the file. The same holds true for the groupname and gid. OPTIONS
-n Do a dry-run and do not create anything on disk. -t Create DIRECTORY (ala mkdir -p) if it does not exist. -s N Strip N path components from a pathname. If the resulting pathname is empty after this operation it is skipped. Be careful however with the following structure: /foo /foo/bar /foo/bar/bla.txt /foo/blork/bla.txt With rdup-up -s2 this will leave: <empty> <empty> /bla.txt /bla.txt And the last 'bla.txt' will overwrite the previous one, this will happen without warnings. -r PATH This option is related to the -s option, but works different. The string PATH is removed from (the beginning of) each pathname. With -r /home/backup the pathname /home/backup/bin/mycmd becomes /bin/mycmd. The same could be done with -s 2, but then you need to count the slashes. Note -s is always performed before -r. -v Be more verbose and echo the processed files to standard output. -vv Be even more verbose and echo processed file and the uid and gid information to standard output. -T Show a table of contents of the rdup stream received (ala tar -tf -). With -T the directory argument is optional. -T unsets any verbose (-v) options. -h A short help message. -V Show the version. EXIT CODE
rdup-up return a zero exit code on success, otherwise 1 is returned. AUTHOR
Written by Miek Gieben. REPORTING BUGS
Report bugs to <miek@miek.nl>. SEE ALSO
http:/www.miek.nl/projects/rdup/ is the main site of rdup. Also see rdup(1), rdup-tr(1) and rdup-backups(7). COPYRIGHT
Copyright (C) 2005-2010 Miek Gieben. This is free software. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Licensed under the GPL version 3. See the file LICENSE in the source distribution of rdup. 1.1.11 13 Dec 2008 RDUP-UP(1)
All times are GMT -4. The time now is 06:05 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy