I am trying to use the two files shown below to either remove or rename contents in one of those files. If in file1.txt $5 matches $5 of file2.txt and the value in $1 of file1.txt is not "No Match" then that value is substituted for all values in $5 and $1 of file2.txt. If however in $1 of file1.txt the value is "No Match", then the row in file2.txt with that in it and the one below it are removed. Thank you .
Contents of file1.txt
Contents of file2.txt
For example,
"DTE3504500000004" is the value of $5 in file1.txt and that matches row 3 of file2.txt $5 , since the value in $1 of file1.txt is "No Match", rows 3 and 4 are removed from file2.txt.
"DTE3504500000005" is the value of $5 in file1.txt and that matches row 9 of file2.txt $5 , since the value in $1 of file1.txt is not "No Match", rather "PXL-A0000005" that new value is used to replace all occurrences of the old value.
The first line in file1.txt has DTE3504500000004 in field 5. From your description (with the 1st field on that line being No Match), the last four lines of file2.txt should have been removed; not the 3rd and 4th lines.
The second line in file1.txt has DTE3504500000005 in field 5. Since that string does not appear in file2.txt, why should anything in file2.txt be changed because of that line?
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 .
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.
Assuming that when you said:
is what is in combine.txt, you really meant that the file you referred to as combine.txt is really named file1.txt (rather than the first line of combine.txt containing the line file1.txt, then maybe something like:
will do what you want.
If you want to try this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk.
This User Gave Thanks to Don Cragun For This Post:
Assuming that when you said:
is what is in combine.txt, you really meant that the file you referred to as combine.txt is really named file1.txt (rather than the first line of combine.txt containing the line file1.txt, then maybe something like:
will do what you want.
If you want to try this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk.
Holy shit.
Moderator's Comments:
edit by bakunin: please note that swearing is not allowed in our forum. I can understand that you are being impressed by Don Craguns awk skills (he manages to make me stand in awe every time he exerts them) but nevertheless i ask you to voice your admiration in a more family-compatible fashion.
Furthermore, contentless posts like yours are not welcome in our forums. Please consider other ways, like, for instance, using the "thanks"-feature on Dons posting. Thank you for your consideration.
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)
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)
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)
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)
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)
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)
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)
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)
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)