Delete lines according to a key words in that line


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Delete lines according to a key words in that line
# 1  
Old 09-09-2013
Delete lines according to a key words in that line

HI, I have a file A like this:
Code:
c 1
length 14432
width 3434
temp 34
c 2
length 3343
width 0923
height 9383
hm 902
temp34
c 3
length 938
height 982
hm 9292
temp 23
...

and B file like this:
Code:
length
height
temp


How can i get a C file like this:
Code:
c 1
width 3434
c 2
width 0923
hm 902
c 3
hm 9292

Thanks!!!
# 2  
Old 09-09-2013
Code:
grep -v -f bfile afile > newfile

Try that
# 3  
Old 09-09-2013
You can try awk solution

Code:
akshay@Lenovo-E49:~$ cat A 
c 1
length 14432
width 3434
temp 34
c 2
length 3343
width 0923
height 9383
hm 902
temp34
c 3
length 938
height 982
hm 9292
temp 23

Code:
akshay@Lenovo-E49:~$ cat B
length
height
temp

Code:
akshay@Lenovo-E49:~$ awk 'FNR==NR{REMOVE[$1]++;next}{a=$1;gsub(/[0-9]/,x,a)}{if(!(a in REMOVE))print $0}' B  A
c 1
width 3434
c 2
width 0923
hm 902
c 3
hm 9292

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete lines containing key words dynamically

Hi Frens, I have a requirement where I need to delete lines having key words and am using the below command to do that sed '/UNIX/d' inputfile > output But now I have one more requirement where in there will be one reference file which has the ID's to be deleted from the master file. ... (3 Replies)
Discussion started by: weknowd
3 Replies

2. 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

3. Shell Programming and Scripting

Search words in a line and print next 15 lines.

I have a text file ( basically a log file) and i have 2 words (alpha, beta), Now i want to search these two words in one line and then print next 15 lines in a temp file. there would be many lines with alpha and beta But I need only last occurrence with "alpha" and "beta" and next 15 lines. ... (4 Replies)
Discussion started by: kashif.live
4 Replies

4. Shell Programming and Scripting

Delete all lines after a specific line ?

Hello. My file is like this: a b c d e f g h i I want to delete all lines after the 3rd line, means after the "c". Is there any way to do this? The lines differ between them and the lines I want to delete does not have a specific word, or the lines I want to keep (a,b,c) does not have a... (4 Replies)
Discussion started by: hakermania
4 Replies

5. Shell Programming and Scripting

delete repeated strings (tags) in a line and concatenate corresponding words

Hello friends! Each line of my input file has this format: word<TAB>tag1<blankspace>lemma<TAB>tag2<blankspace>lemma ... <TAB>tag3<blankspace>lemma Of this file I need to eliminate all the repeated tags (of the same word) in a line, as in the example here below, but conserving both (all) the... (2 Replies)
Discussion started by: mjomba
2 Replies

6. Shell Programming and Scripting

Delete lines where line length is < x

Hi all, I am using Sed to convert a log file into a csv, so far so good. Kudos to this forum for helping me thus far! My current problem. There are some lines in the log file that I do not want. How can I delete lines where the line legth is less than say 100? Here are some sample lines... (6 Replies)
Discussion started by: Mr. Rocco
6 Replies

7. Shell Programming and Scripting

Delete lines with line numbers.

Hi, I have a file will 1000 lines.... I want to deleted some line in the file... like 800-850 lines i want to remove in that... can somebody help me..? thanks. (2 Replies)
Discussion started by: Kattoor
2 Replies

8. Shell Programming and Scripting

How can i delete some words in every line in a file

Hi, I need help to delete a few words in every line in my file. This is how the file look like: VDC DQ 14900098,,,,157426.06849776753,786693.2919373367 10273032,,,,157525.49445429695,776574.5546672409 VDC DG ,10273033,,3er55,,149565.57096061576,801778.9379555212 AS174 892562,,,,, ... (2 Replies)
Discussion started by: andy_s
2 Replies

9. Shell Programming and Scripting

search 2 lines and delete above line

Hi, I've been searching in this forum for the last 4 hours trying to do one thing: search 2 lines and delete the above line. So far I have not be able to find something similar in this forum, so I need help. This is what I'm trying to do. For example, I have a file called file1: file1 word1... (4 Replies)
Discussion started by: shamushamu
4 Replies

10. Shell Programming and Scripting

Delete lines that contain 3 or more words?

How can I delete lines that contain 3 or more words? I have a file, old.txt, that has multi-word phrases in it and I want to remove the lines with 3 words or more and send the output to new.txt. I've tried the following using sed but it doesn't seem to work: sed '/(\b\w+\b){3,}/d' old.txt >... (5 Replies)
Discussion started by: revax
5 Replies
Login or Register to Ask a Question