awk find and delete line from list


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk find and delete line from list
# 8  
Old 11-22-2017
I'm glad it's working for you now.

Note that if you expect all lines in file.txt to be matched by a line in input.txt and you want file.txt to be an empty file in that case; change the command list to be:
Code:
grep -f input.txt -v file.txt > file; [ $? -le 1 ] && mv file file.txt

You need to do this because the exit code from grep is 1 if no input lines are copied to the output file, but no errors occurred. (This is why file wasn't moved to file.txt when file was empty.)
This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

How to find a string in a line in UNIX file and delete that line and previous 3 lines ?

Hi , i have a file with data as below.This is same file. But actual file contains to many rows. i want to search for a string "Field 039 00" and delete that line and previous 3 lines in that file.. Can some body suggested me how can i do using either sed or awk command ? Field 004... (7 Replies)
Discussion started by: vadlamudy
7 Replies

2. Shell Programming and Scripting

awk delete line if $5 contains string from list

(5 Replies)
Discussion started by: chrisjorg
5 Replies

3. Shell Programming and Scripting

Find specific line and delete line after.

I'm looking for a way to search a file, in this case init.rc for a specific match, service adbd /sbin/adbd, and delete the a specific line after it Original: # adbd is controlled by the persist.service.adb.enable system property service adbd /sbin/adbd disabled After deletion: #... (5 Replies)
Discussion started by: GabrialDestruir
5 Replies

4. Shell Programming and Scripting

Find and delete rest of the line

i need to find ' - ' in a line , if i found i need to rest of the line including '-' example libmm-2.0 libytytsunos-5.6 output libmm libytytsunos (7 Replies)
Discussion started by: girija
7 Replies

5. UNIX for Dummies Questions & Answers

Find Pattern delete line and next line

I am trying to delete the line with pattern and the next line. Found the below command in forum which also deleted the previous line. how should i modify that to make sure that only the line with pattern and the next line are deleted but not the previous line? awk '/key... (1 Reply)
Discussion started by: rdhanek
1 Replies

6. UNIX for Advanced & Expert Users

Urgent Help required : awk/sed help to find pattern and delete till end of line

Hi, I need help with using an awk or sed filter on the below line ALTER TABLE "ACCOUNT" ADD CONSTRAINT "ACCOUNT_PK" PRIMARY KEY ("ACCT_ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUPS 1) TABLESPACE "WMC_DATA" LOGGING ENABLE Look for... (1 Reply)
Discussion started by: rajan_san
1 Replies

7. Shell Programming and Scripting

Urgent! Sed/Awk Filter Find Pattern Delete Till End Of Line

Hi, I need help with using an awk or sed filter on the below line ALTER TABLE "ACCOUNT" ADD CONSTRAINT "ACCOUNT_PK" PRIMARY KEY ("ACCT_ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUPS 1) TABLESPACE "WMC_DATA" LOGGING ENABLE Look for... (2 Replies)
Discussion started by: rajan_san
2 Replies

8. UNIX for Advanced & Expert Users

Find and delete the line

Hi I have a text file like this name today.txt the request has been accepted the scan is successful at following time there are no invalid packages 5169378 : map : Permission Denied the request has been accepted Now what i want do is I want to search the today.txt file and if i... (8 Replies)
Discussion started by: gsusarla
8 Replies

9. Shell Programming and Scripting

find a line and delete it.

Hi All, I would like to fine some entry in a file, if it found, it should remove the same in the same file. Please some one help me. need to find and en entry 'bea' from hosts file. If it found it should write it same host file. but i am not geting it. If i am writing it in new file... (2 Replies)
Discussion started by: bullz26
2 Replies

10. UNIX for Dummies Questions & Answers

Find a word and delete the line

Hi I have a text file like this name today.txt the request has been accepted the scan is successful at following time there are no invalid packages 5169378 : map : Permission Denied the request has been accepted Now what i want do is I want to search the today.txt file and if i... (1 Reply)
Discussion started by: gsusarla
1 Replies
Login or Register to Ask a Question