Simple way to delete


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Simple way to delete
# 1  
Old 05-17-2009
Simple way to delete

With file2 search for all data in file1 then delete matched pattern in file1.Length of each record is like 30. As there is no constant string in file2 how to search and delete in file1. Is that we can do it by sed or grep cmds?
# 2  
Old 05-17-2009
Can you give some examples? a sample i/p and o/p
# 3  
Old 05-17-2009
cat file1
S24545ATTFCTA197000022238
S24547ATTFCTA196000022185
F24902ATTFCTBA0D000024481
A41105SCEKEIA212000004753
S41632SCEKENA001000003577

w41642SCEKEIA309000003214
G41905SCEKEIBA03000010883
K58410SCEKENA326000004960
M58427SCEKENA298000005536
some more records...

cat file2
A41105SCEKEIA212000004753
S41632SCEKENA001000003577

some more records...

O/P (exculde all records from file2)
S24545ATTFCTA197000022238
S24547ATTFCTA196000022185
F24902ATTFCTBA0D000024481
w41642SCEKEIA309000003214
G41905SCEKEIBA03000010883
K58410SCEKENA326000004960
M58427SCEKENA298000005536
some more records...
# 4  
Old 05-17-2009
Code:
awk 'FNR==NR{a[$0];next}(!($0 in a))' file2 file1

# 5  
Old 05-17-2009
Or with grep:

Code:
grep -vf file2 file1

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Rsync with --delete but do not delete peer dirs on target

rsync with --delete won't honor the delete if the source is something/*. I want the delete to work, but not to delete directories on the target that are peer to the intended directory. For example, using these source and target file structures: Source on desktop: ~/ Money/ ... (4 Replies)
Discussion started by: JavaMeister
4 Replies

2. Programming

Mismatched free() / delete / delete [] line no missing

Could you tell me the possibilities of the reason to get the Mismatched free() / delete / delete . I unable to see the line no in the valgrind report. it displays the function name. with that function name, I am not able to find where exactly the issue is there.I am getting the Mismatched free()... (3 Replies)
Discussion started by: SA_Palani
3 Replies

3. Shell Programming and Scripting

Seemingly simple sed, delete between matching lines

There are many matching blocks of text in one file that need to be deleted. This example below is one block that needs to be either deleted or replaced with an empty line. This text below is the input file. The ouput file should be empty Searching Checks. Based on search criteria name: Value :... (2 Replies)
Discussion started by: bash_in_my_head
2 Replies

4. Shell Programming and Scripting

Script needed to delete to the list of files in a directory based on last created & delete them

Hi My directory structure is as below. dir1, dir2, dir3 I have the list of files to be deleted in the below path as below. /staging/retain_for_2years/Cleanup/log $ ls -lrt total 0 drwxr-xr-x 2 nobody nobody 256 Mar 01 16:15 01-MAR-2015_SPDBS2 drwxr-xr-x 2 root ... (2 Replies)
Discussion started by: prasadn
2 Replies

5. Red Hat

Syslog.conf: looking for a simple answer on a simple question

Cheers! In /etc/syslog.conf, if an error type is not specified, is it logged anywhere (most preferable is it logged to /var/log/messages) or not? To be more precise I am interested in error and critical level messages. At default these errors are not specified in syslog.conf, and I need to... (6 Replies)
Discussion started by: dr1zzt3r
6 Replies

6. Shell Programming and Scripting

Help making simple perl or bash script to create a simple matrix

Hello all! This is my first post and I'm very new to programming. I would like help creating a simple perl or bash script that I will be using in my work as a junior bioinformatician. Essentially, I would like to take a tab-delimted or .csv text with 3 columns and write them to a "3D" matrix: ... (16 Replies)
Discussion started by: torchij
16 Replies

7. Shell Programming and Scripting

Simple to you not simple to me pattern matchin help

hey all, im new and my first question is: say i have a word "blahblah" how do i get and replace the last letter of the word with say k, so replace the h with a k. However you cant just replace the h it has to change the LAST LETTER of the word. Cheers In advance. :b: (0 Replies)
Discussion started by: aleks001
0 Replies

8. Programming

Simple C question... Hopefully it's simple

Hello. I'm a complete newbie to C programming. I have a C program that wasn't written by me where I need to write some wrappers around it to automate and make it easier for a client to use. The problem is that the program accepts standard input to control the program... I'm hoping to find a simple... (6 Replies)
Discussion started by: Xeed
6 Replies

9. UNIX for Dummies Questions & Answers

Simple vi delete question

hi I was looking in the net for answer for this simple question but with no lock in vi how can I delete all the lines up to where im standing with the curser whiteout counting the lines example say im standing with the courser in line 5 I want to delete all the lines from end of the file up... (3 Replies)
Discussion started by: umen
3 Replies

10. UNIX for Dummies Questions & Answers

Ok simple question for simple knowledge...

Ok what is BSD exactly? I know its a type of open source but what is it exactly? (1 Reply)
Discussion started by: Corrail
1 Replies
Login or Register to Ask a Question