Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Remove lines containing strings from a file Post 303044353 by mohtashims on Thursday 20th of February 2020 02:55:19 AM
Old 02-20-2020
Remove lines containing strings from a file

Experts Hi,

I wish to remove lines containing the following strings from a file hello.out and save it in new_hello.out file.

Code:
1. text4
2. text5
3. text11
4. file13
5. file15
6. text16

The below works however, is it possible to club all the grep -v into a single grep -v ?

Code:
cat hello.out | grep -v text4 | grep -v text5 | grep -v text11 | grep -v text16 | grep -v file13 | grep -v file15 > new_hello.out

I'm aware of of using grep -E and clubbing multiple strings however I'm not sure of grep -v

I'm on Redhat Linux 7.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extracting the lines between 2 strings of a file

Hi, I have a sql file and i need to extract the table names used in the sql file using a unix script. If i can extract the lines between the keywords 'FROM' and 'WHERE' in the file, my job is done. can somebody tell me how to do this using a shell script. If u can just let me know, how to... (2 Replies)
Discussion started by: babloo
2 Replies

2. UNIX for Dummies Questions & Answers

Counting no of lines between two strings in a file

Hi all, I'm very very new to UNIX and AWK world.Please help me in finding a solution for my problem. I'm having a file like this ----------------------------------------------------------------- ~Version Information VERS. 2.0: CWLS log ASCII Standard -VERSION 2.0 WRAP. ... (4 Replies)
Discussion started by: santyshyam
4 Replies

3. Shell Programming and Scripting

Remove matching lines with list of strings

Hi, HP-UX gxxxxxxxc B.11.23 U ia64 3717505098 unlimited-user license I have a file with below pipe separated field values: xxx|xxx|abcd|xxx|xxx|xx xxx|xxx|abcd#123|xxx|xxx|xx xxx|xxx|abcd#345|xxx|xxx|xx xxx|xxx|pqrs|xxx|xxx|xx xxx|xxx|pqrs#123|xxx|xxx|xx The third field has values like... (6 Replies)
Discussion started by: Nanu_Manju
6 Replies

4. Shell Programming and Scripting

different take on common ?: search for two strings and remove lines between them

Thank you for assisting, I've got a partial solution just needs a tweak. Hulk-BASH$ cat somefile.txt oh there is some stuff here some more stuff here START_LABEL stuff I want more stuff I want END_LABEL other stuff here too and even more stuff here too Hulk-BASH$ Hulk-BASH$ sed... (8 Replies)
Discussion started by: laser
8 Replies

5. Shell Programming and Scripting

Adding strings to lines in a file

Hi all, I have a positional text file that comes from some source application. Before it is processed by destination application I have to add some header (suffix) to every record(line) in the file. e.g. Actual File ............... AccountDetails AcNO Name Amount 1234 John 26578 5678... (3 Replies)
Discussion started by: sharath160
3 Replies

6. Shell Programming and Scripting

Read file and remove special characters or strings

Hello all I am getting data like col1 | col2 | col3 asdafa | asdfasfa | asf*&^sgê 345./ |sdfasd23425^%^&^ | sdfsa23 êsfsfd | sf(* | sdfsasf My requirement is like I have to to read the file and remove all special characters and hex characters ranging form 00-1f from 1st column, remove %"'... (1 Reply)
Discussion started by: vasuarjula
1 Replies

7. Shell Programming and Scripting

How to remove lines containing strings

Hi Guys, I need some script in removing lines containing strings like ",, ," and "rows". Retain only numbers as the output. See below for the input and output file. INPUT FILE: 9817 9832 6285 6312 6313 6318 ,, , 6329 7078 7098 7130 7959 7983 (7 Replies)
Discussion started by: pinpe
7 Replies

8. Shell Programming and Scripting

Delete lines in file containing duplicate strings, keeping longer strings

The question is not as simple as the title... I have a file, it looks like this <string name="string1">RZ-LED</string> <string name="string2">2.0</string> <string name="string2">Version 2.0</string> <string name="string3">BP</string> I would like to check for duplicate entries of... (11 Replies)
Discussion started by: raidzero
11 Replies

9. Shell Programming and Scripting

Compare one files with strings from another + remove lines

Have two files and want to compare the content of file1 with file2. When matched remove the line. awk 'NR==FNR {b; next} !(b in $0)' file1 file2file1 1. if match 2. removefile2 1. this line has to be removed if match 2. this line has a match, remove 3. this line has no match, no removingThe... (3 Replies)
Discussion started by: sdf
3 Replies

10. Shell Programming and Scripting

Remove lines containing 2 or more duplicate strings

Within my text file i have several thousand lines of text with some lines containing duplicate strings/words. I would like to entirely remove those lines which contain the duplicate strings. Eg; One and a Two Unix.com is the Best This as a Line Line Example duplicate sentence with the word... (22 Replies)
Discussion started by: martinsmith
22 Replies
DGLOB(1)						   Debian-goodies documentation 						  DGLOB(1)

NAME
dglob - Expand package names or files matching a pattern SYNOPSIS
dglob [-a] pattern dglob [-0] -f pattern DESCRIPTION
dglob lists packages names matching a pattern. It can also list all the files they contain. By default dglob only searches installed packages; the -a switch widens the search (see "OPTIONS"). The list is written to stdout, one name per line. grep-dctrl(1) and grep-aptavail(1) are used to search the list of packages, so you should refer to its documentation for information on how patterns are matched. By default, all packages whose name contains the given string will be matched, but several options are available to modify this behavior (see "OPTIONS"). If you use dglob with the -f option, all files in the matched packages are listed instead of their names. If you do not use de -a switch, only existing, plain (i.e. no symlinks, directories or other special ones) files are listed. If the -a switch is use then all files will be listed both for installed and non-installed packages. The filenames are written to stdout, one file per line. You can use the -0 option to get the filenames separated by '' instead of a newline. OPTIONS
dglob supports the following options: -a Search through all available packages, not just installed ones. If set, grep-aptavail(1) is used. -f List all files in the matched packages. By default, this lists only installed (i.e. locally existing) files from installed packages. If used together with -a then it will list all files both of installed and non-installed packages by mean of apt-file(1). If apt-file is not installed, using -f together with -a is rather pointless. -0 When listing files (with -f) use '' as a separator instead of a newline. When specified without -f, this options does nothing. -r, -e, -i, -X, -v These options are passed directly to grep-dctrl(1) or to grep-aptavail(1) to modify how the pattern is matched. See grep-dctrl(1). FILES
/var/lib/dpkg/status dpkg(8) status file, which serves as source for the list of available and installed packages. AUTHOR
Matt Zimmerman <mdz@debian.org> This manpage was written by Frank Lichtenheld <frank@lichtenheld.de>, and further enhanced by Javier Fernandez-Sanguino <jfs@debian.org>. COPYRIGHT AND LICENCE
Copyright (C) 2001 Matt Zimmerman <mdz@debian.org>. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. On Debian systems, a copy of the GNU General Public License may be found in /usr/share/common-licenses/GPL. SEE ALSO
grep-dctrl(1), grep-available(1), apt-file(1), dpkg(8) perl v5.14.2 2012-03-21 DGLOB(1)
All times are GMT -4. The time now is 05:19 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy