Sponsored Content
Top Forums Shell Programming and Scripting A way to delete specific lines Post 302472277 by Scott on Tuesday 16th of November 2010 05:21:42 PM
Old 11-16-2010
Your question is somewhat vague. Not all of the lines you print are of the same length:
Code:
$ awk '{print length}' file1
136
136
99
99
99
136
135
99
99
136
$ awk 'length == 136' file1               
"2010-07-26","2010","07","26","*","26.90","","13.10","","20.00","","0.00","","2.00","","","M","","M","0.60","","","","0.00","","0.00",""
"2010-07-27","2010","07","27","*","26.80","","15.30","","21.10","","0.00","","3.10","","","M","","M","0.90","","","","0.00","","0.00",""
"2010-07-31","2010","08","06","*","25.40","","12.20","","18.80","","0.00","","0.80","","","M","","M","0.00","","","","0.00","","0.00",""
"2010-08-04","2010","07","28","*","30.10","E","17.30","E","23.70","E","0.00","E","5.70","E","","M","","M","6.90","E","","","","M","","M"

136, as far as fixed-length, gives the closest match.

Last edited by Scott; 11-16-2010 at 06:32 PM.. Reason: Wording
 

10 More Discussions You Might Find Interesting

1. Programming

Delete specific lines in a text file

Hi, experts, I would like to create a function that can calculate the total number of lines in a saved text file and delete specific lines in that particular file (I only want the last few lines). Hav anybody have the experience and giv me a hand in this? (9 Replies)
Discussion started by: dniz
9 Replies

2. UNIX for Advanced & Expert Users

How to delete specific lines at the same time

Dear All I have a pattern which look like this: 2 20080312_10:55:35.800 Spain-Telefonica ISC 9 IAM 927535957 34670505334 f 275 COT b 700 ACM b 6577 CPG b 10726 ANM b 202195 REL f 202307 RLC :COMMA: NCI=15,FCI=2101,CPC=0A,TMR=00,USI,OFI=00: :COMMB: BCI=0214,OBI=01,ACT: :RELCAUSE:10: This... (1 Reply)
Discussion started by: zanetti321
1 Replies

3. Shell Programming and Scripting

delete lines containing a specific word in afile

Hi, Please suggest how to write a shell script which delets all the lines containing the word unix in the files supplied as argument in the shell. (4 Replies)
Discussion started by: sireesha9
4 Replies

4. Shell Programming and Scripting

Delete specific lines from a file

Hi, I have a file ( all_users.ldif ) of the following format: cn=orcladmin, cn=Users, dc=maximus,dc=com cn=PUBLIC, cn=Users, dc=maximus,dc=com cn=portal,cn=users,dc=maximus,dc=com cn=portal_admin,cn=users,dc=maximus,dc=com cn=uddi_publisher,cn=Users,dc=maximus,dc=com... (4 Replies)
Discussion started by: itzz.me
4 Replies

5. Shell Programming and Scripting

How to delete all lines before a specific word?

Let's say we have a file containing: alllllsadfsdasdf qwdDDDaassss ccxxcxc#2222 dssSSSSddDDDD D1Sqn2NYOHgTI Hello Alex ssS@3 Ok, and let's say we want to delete all words from D1Sqn2NYOHgTI and back, this means to delete the words (and the lines of them) : alllllsadfsdasdf... (2 Replies)
Discussion started by: hakermania
2 Replies

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

7. Shell Programming and Scripting

Delete multiple lines starting with a specific pattern

Hi, just tried some script, awk, sed for the last 2 hours and now need help. Let's say I have a huge file of 800,000 lines like this : It's a tedious job to look through it, I'd like to remove those useless lines in it as there's a few thousands : Or to be even more precise : if line1 =... (6 Replies)
Discussion started by: Zurd
6 Replies

8. UNIX for Dummies Questions & Answers

How to delete specific lines (2n+3 line, n=0,1,2...296) in a file?

Dear everyone, I have a file with 900 lines (there is only numbers in one line, no string), I only need the lines 2+3n (n=0,1...296), i.e line 2, 5, 8, 11...888. I tried google but only the results such as how to delete all the odd lines or all the even lines with 'awk' command. Thanks in... (4 Replies)
Discussion started by: phamnu
4 Replies

9. Shell Programming and Scripting

How to delete lines starting with specific string?

Dear all, I would like to delete even lines starting with "N" together with their respective titles which are actually odd lines. Below is the example of input file. I would like to remove line 8 and 12 together with its title line, i.e., line 7 and 11, respectively.... (2 Replies)
Discussion started by: huiyee1
2 Replies

10. Shell Programming and Scripting

Delete lines above and below specific line of text

I'm trying to remove a specific number of lines, above and below a specific line of text, highlighted in red: <STMTTRN> <TRNTYPE>CREDIT <DTPOSTED>20151205000001 <TRNAMT>10 <FITID>667800001 <CHECKNUM>667800001 <MEMO>BALANCE </STMTTRN> <STMTTRN> <TRNTYPE>DEBIT <DTPOSTED>20151207000001... (8 Replies)
Discussion started by: bomsom
8 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:31 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy