Sponsored Content
Top Forums Shell Programming and Scripting How to remove lines containing strings Post 302535962 by pinpe on Sunday 3rd of July 2011 10:51:27 AM
Old 07-03-2011
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:
Code:
9817
9832
6285
6312
6313
6318
,,  ,
6329
7078
7098
7130
7959
7983
1253
1254
1257
,,  ,
,rows,selected
,,  ,





DESIRED OUTPUT FILE:
Code:
9817
9832
6285
6312
6313
6318
6329
7078
7098
7130
7959
7983
1253
1254
1257


Thanks in advance.


Br,
Pinpe
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

using AWK see the upper lines and lower lines of the strings??

Hi experts, You cool guys already given me the awk script below- awk '/9366109380/,printed==5 { ++printed; print; }' 2008-09-14.0.log Morever, i have one more things- when i awk 9366109380, i can also see the Upper 3 lines as well as below 5 lines of that string. Line 1.... (3 Replies)
Discussion started by: thepurple
3 Replies

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

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

4. Shell Programming and Scripting

Grep and delete lines except the lines with strings

Hi I am writing a script which should read a file and search for certain strings 'approved' or 'removed' and retain only those lines that contain the above strings. Ex: file name 'test' test: approved package waiting for approval package disapproved package removed package approved... (14 Replies)
Discussion started by: vj8436
14 Replies

5. Shell Programming and Scripting

Removing empty lines(space) between two lines containing strings

Hi, Please provide shell script to Remove empty lines(space) between two lines containing strings in a file. Input File : A1/EXT "BAP_BSC6/07B/00" 844 090602 1605 RXOCF-465 PDTR11 1 SITE ON BATTERY A2/EXT... (3 Replies)
Discussion started by: sudhakaryadav
3 Replies

6. Shell Programming and Scripting

How to remove unwanted strings?

Hi Guys, Can someone give me a hand on how I can remove unwanted strings like "<Number>" and "</Number>" and retain only the numbers from the input file below. INPUT FILE: <Number>10050000</Number> <Number>1001340001</Number> <Number>1001750002</Number> <Number>100750003</Number>... (8 Replies)
Discussion started by: pinpe
8 Replies

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

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

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

10. Shell Programming and Scripting

awk to remove lines that do not start with digit and combine line or lines

I have been searching and trying to come up with an awk that will perform the following on a converted text file (original is a pdf). 1. Since the first two lines are (begin with) text they are removed 2. if $1 is a number then all text is merged (combined) into one line until the next... (3 Replies)
Discussion started by: cmccabe
3 Replies
FILTERDIFF(1)							     Man pages							     FILTERDIFF(1)

NAME
filterdiff - extract or exclude diffs from a diff file SYNOPSIS
filterdiff [[-i PATTERN] | [--include=PATTERN]] [[-I FILE] | [--include-from-file=FILE]] [[-p n] | [--strip-match=n]] [--strip=n] [--addprefix=PREFIX] [--addoldprefix=PREFIX] [--addnewprefix=PREFIX] [[-x PATTERN] | [--exclude=PATTERN]] [[-X FILE] | [--exclude-from-file=FILE]] [[-v] | [--verbose]] [--clean] [[-z] | [--decompress]] [[-# RANGE] | [--hunks=RANGE]] [--lines=RANGE] [--files=RANGE] [--annotate] [--format=FORMAT] [--as-numbered-lines=WHEN] [--remove-timestamps] [file...] filterdiff {[--help] | [--version] | [--list] | [--grep ...]} DESCRIPTION
You can use filterdiff to obtain a patch that applies to files matching the shell wildcard PATTERN from a larger collection of patches. For example, to see the patches in patch-2.4.3.gz that apply to all files called lp.c: filterdiff -z -i '*/lp.c' patch-2.4.3.gz If neither -i nor -x options are given, -i '*' is assumed. This way filterdiff can be used to clean up an existing diff file, removing redundant lines from the beginning (eg. the text from the mail body) or between the chunks (eg. in CVS diffs). To extract pure patch data, use a command like this: filterdiff message-with-diff-in-the-body > patch Note that the interpretation of the shell wildcard pattern does not count slash characters or periods as special (in other words, no flags are given to fnmatch). This is so that "*/basename"-type patterns can be given without limiting the number of pathname components. You can use both unified and context format diffs with this program. OPTIONS
-i PATTERN, --include=PATTERN Include only files matching PATTERN. All other lines in the input are suppressed. -I FILE, --include-from-file=FILE Include only files matching any pattern listed in FILE, one pattern per line. All other lines in the input are suppressed. -x PATTERN, --exclude=PATTERN Exclude files matching PATTERN. All other lines in the input are displayed. -X FILE, --exclude-from-file=FILE Exclude files matching any pattern listed in FILE, one pattern per line. All other lines in the input are displayed. -p n, --strip-match=n When matching, ignore the first n components of the pathname. -# RANGE, --hunks=RANGE Only include hunks within the specified RANGE. Hunks are numbered from 1, and the range is a comma-separated list of numbers or "first-last" spans; either the first or the last in the span may be omitted to indicate no limit in that direction. --lines=RANGE Only include hunks that contain lines from the original file that lie within the specified RANGE. Lines are numbered from 1, and the range is a comma-separated list of numbers or "first-last" spans; either the first or the last in the span may be omitted to indicate no limit in that direction. --files=RANGE Only include files indicated by the specified RANGE. Files are numbered from 1 in the order they appear in the patch input, and the range is a comma-separated list of numbers or "first-last" spans; either the first or the last in the span may be omitted to indicate no limit in that direction. --annotate Annotate each hunk with the filename and hunk number. --format=unified|context Use specified output format. --strip=n Remove the first n components of pathnames in the output. --addprefix=PREFIX Prefix pathnames in the output by PREFIX. This will override any individual settings specified with the --addoldprefix or --addnewprefix options. --addoldprefix=PREFIX Prefix pathnames for old or original files in the output by PREFIX. --addnewprefix=PREFIX Prefix pathnames for updated or new files in the output by PREFIX. --as-numbered-lines=before|after Instead of a patch fragment, display the lines of the selected hunks with the line number of the file before (or after) the patch is applied, followed by a TAB character and a colon, at the beginning of each line. Each hunk except the first will have a line consisting of "..." before it. --remove-timestamps Do not include file timestamps in the output. -v, --verbose Always show non-diff lines in the output. By default, non-diff lines are only shown when excluding a filename pattern. --clean Always remove all non-diff lines from the output. Even when excluding a filename pattern. -z, --decompress Decompress files with extensions .gz and .bz2. --help Display a short usage message. --version Display the version number of filterdiff. --list Behave like lsdiff(1) instead. --grep Behave like grepdiff(1) instead. EXAMPLES
To see all patch hunks that affect the first five lines of a C file: filterdiff -i '*.c' --lines=-5 < patch To see the first hunk of each file patch, use: filterdiff -#1 patchfile To see patches modifying a ChangeLog file in a subdirectory, use: filterdiff -p1 Changelog To see the complete patches for each patch that modifies line 1 of the original file, use: filterdiff --lines=1 patchfile | lsdiff | xargs -rn1 filterdiff patchfile -i To see all but the first hunk of a particular patch, you might use: filterdiff -p1 -i file.c -#2- foo-patch If you have a very specific list of hunks in a patch that you want to see, list them: filterdiff -#1,2,5-8,10,12,27- To see the lines of the files that would be patched as they will appear after the patch is applied, use: filterdiff --as-numbered-lines=after patch.file You can see the same context before the patch is applied with: filterdiff --as-numbered-lines=before patch.file Filterdiff can also be used to convert between unified and context format diffs: filterdiff -v --format=unified context.diff SEE ALSO
lsdiff(1), grepdiff(1) AUTHOR
Tim Waugh <twaugh@redhat.com> Package maintainer patchutils 23 Jan 2009 FILTERDIFF(1)
All times are GMT -4. The time now is 02:44 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy