Sponsored Content
Top Forums Shell Programming and Scripting Delete lines containing key words dynamically Post 302997528 by weknowd on Monday 15th of May 2017 05:21:17 PM
Old 05-15-2017
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

Code:
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.

Eg:

Master File

Code:
ID,NAME
1,XX
2,YY
3,ZZ
4,DD

Reference File

Code:
ID
2
3

So my output file should be

Code:
ID,NAME
1,XX
4,DD

It would be helpful if you can let me know how we can acheive it dynamically.

Last edited by Don Cragun; 05-16-2017 at 02:26 AM.. Reason: Add CODE tags.
 

10 More Discussions You Might Find Interesting

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

2. Shell Programming and Scripting

SED - delete words between two possible words

Hi all, I want to make an script using sed that removes everything between 'begin' (including the line that has it) and 'end1' or 'end2', not removing this line. Let me paste an 2 examples: anything before any string begin few lines of content end1 anything after anything before any... (4 Replies)
Discussion started by: meuser
4 Replies

3. Shell Programming and Scripting

grep - Extracting multiple key words from stdout

Hello. From command line, the command zypper info nxclient return a bloc of data : linux local # zypper info nxclient Loading repository data... Reading installed packages... Information for package nxclient: Repository: zypper_local Name: nxclient Version: 3.5.0-7 Arch: x86_64... (7 Replies)
Discussion started by: jcdole
7 Replies

4. Shell Programming and Scripting

Extract key words and print their values

Input file (HTTP request log file): GET... (2 Replies)
Discussion started by: buptwy
2 Replies

5. UNIX for Dummies Questions & Answers

Filter logs for key words and create an index

well, im a total novice of unix commands and shell scripting, i never made anything. But yesterday in my work i was working with a lot of log files and i was wondering if there is a command for doing something like this: i have a bunch of files with text like this: blablabla errorcode1... (11 Replies)
Discussion started by: matius_88
11 Replies

6. UNIX for Dummies Questions & Answers

Delete lines according to a key words in that line

HI, I have a file A like this: 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 ... (2 Replies)
Discussion started by: the_simpsons
2 Replies

7. Shell Programming and Scripting

Shell Script @ Find a key word and If the key word matches then replace next 7 lines only

Hi All, I have a XML file which is looks like as below. <<please see the attachment >> <?xml version="1.0" encoding="UTF-8"?> <esites> <esite> <name>XXX.com</name> <storeId>10001</storeId> <module> ... (4 Replies)
Discussion started by: Rajeev_hbk
4 Replies

8. Shell Programming and Scripting

Using key words or symbols to determine parser

There are multiple conditions in which the user can input data. 1. > 2. del 3. ins 4. delins The user input is saved in a specific directory using the code below: Code: cd 'C:' C:/Users/cmccabe/Desktop/Python27/python.exe C:/Users/cmccabe/Desktop/Python27/run_batch_job.py... (12 Replies)
Discussion started by: cmccabe
12 Replies

9. UNIX for Beginners Questions & Answers

Non-root script used search and list specific key words

Hy there all. Im new here. Olso new to terminal & bash, but it seams that for me it's much easyer to undarsatnd scripts than an actual programming language as c or anyother languare for that matter. S-o here is one og my home works s-o to speak. Write a shell script which: -only works as a... (1 Reply)
Discussion started by: Crisso2Face
1 Replies

10. Red Hat

How to block some key words in my url for apache config?

Hi Folks, I am running a website and that needs to be tightened with security in terms of hacking... Whereas, In my URL, when i click on certain links the entire link as contains some words like below:/control_panel /controlpanel /admin /cms Whereas, i need to block those words in apache... (1 Reply)
Discussion started by: gsiva
1 Replies
LOOK(1) 						      General Commands Manual							   LOOK(1)

NAME
look - find lines in a sorted list SYNOPSIS
look [ -dfnixtc ] [ string ] [ file ] DESCRIPTION
Look consults a sorted file and prints all lines that begin with string. It uses binary search. The following options are recognized. Options dfnt affect comparisons as in sort(1). -i Interactive. There is no string argument; instead look takes lines from the standard input as strings to be looked up. -x Exact. Print only lines of the file whose key matches string exactly. -d `Directory' order: only letters, digits, tabs and blanks participate in comparisons. -f Fold. Upper case letters compare equal to lower case. -n Numeric comparison with initial string of digits, optional minus sign, and optional decimal point. -t[c] Character c terminates the sort key in the file. By default, tab terminates the key. If c is missing the entire line comprises the key. If no file is specified, /lib/words is assumed, with collating sequence df. FILES
/lib/words SOURCE
/sys/src/cmd/look.c SEE ALSO
sort(1), grep(1) DIAGNOSTICS
The exit status is "not found" if no match is found, and "no dictionary" if file or the default dictionary cannot be opened. LOOK(1)
All times are GMT -4. The time now is 05:06 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy