12-19-2011
Extracting Multiple Lines from a Text File
Hello. I am sorry if this is a common question but through all my searching, I haven't found an answer which matches what I want to do.
I am looking for a sed command that will parse through a large text file and extract lines that start with specific words (which are repeated throughout the file).
Example Text
Line 1: This is example line 1
Line 2: This is example line 2
Line 3: This is example line 3
Line 4: This is example line 4
Line 5: This is example line 5
<blankline>
Line 1: This is example line 1
Line 2: This is example line 2
Line 3: This is example line 3
Line 4: This is example line 4
Line 5: This is example line 5
<blankline>
Line 1: This is example line 1
Line 2: This is example line 2
Line 3: This is example line 3
Line 4: This is example line 4
Line 5: This is example line 5
etc.
Output Needed (in a new text file):
Line 2: This is example line 2
Line 4: This is example line 4
<blankline>
Line 2: This is example line 2
Line 4: This is example line 4
<blankline>
Line 2: This is example line 2
Line 4: This is example line 4
etc.
I tried grep but couldn't get the command to understand the separate lines.
Again, sorry if this is an obvious answer but finding it fails me.
Thanks.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I have a file with 14million lines and I would like to extract all the unique lines from the file into another text file.
For example:
Contents of file1
happy
sad
smile
happy
funny
sad
I want to run a command against file one that only returns the unique lines (ie 1 line for happy... (3 Replies)
Discussion started by: soliberus
3 Replies
2. UNIX for Dummies Questions & Answers
Hi,
I'm trying to remove multiple lines of text based off a series of different words and output it to a new file
The document contains a ton of data but i want to delete any line that has the following
mx1.rr.biz.com or ns2.ri.biz.com
i tried using grep -v filename "mx1.rr.biz.com" >... (3 Replies)
Discussion started by: spartan22
3 Replies
3. Shell Programming and Scripting
I am attempting to insert multiple lines of text into a specific place in a text file based on the lines above or below it.
For example, Here is a portion of a zone file.
IN NS ns1.domain.tld.
IN NS ns2.domain.tld.
IN ... (2 Replies)
Discussion started by: cdn_humbucker
2 Replies
4. UNIX for Dummies Questions & Answers
Hi all,
I need to extract lines between the lines 'RD' and 'QA' from a text file (following). there are more that one of such pattern in the file and I need to extract all of them. however, the number of lines between them is varied in the file. Therefore, I can not just use 'grep -A' command.... (6 Replies)
Discussion started by: johnshembb
6 Replies
5. UNIX for Dummies Questions & Answers
Hello,
I want to create a file whose content is multiple lines of strings.
The string has the following pattern:
aaaa/bbbb/A-B.txt
A is a variable ranges from A1 to A2
B is a variable ranges from B1 to B2
Any ideas?
Thanks. (17 Replies)
Discussion started by: vic005
17 Replies
6. Shell Programming and Scripting
Hi All
I have text file like this:
a=21ej
c=3tiu32
e=hydkehw
f=hgdiuw
g=jhdkj
a=klkjhvl
b=dlkjhyfd
a=yo
c=8732
Any way I can process data from first a to just before of second a, and then second a to just before of 3rd one.
Just fetching records like that will help, I mean... (3 Replies)
Discussion started by: sandipjee
3 Replies
7. UNIX for Dummies Questions & Answers
I would like to use grep to select multiple lines from a text file using a single-column text file. Basically I want to only select lines from the first text file where the second column of the first text file matches the second text file. How do I go about doing that? Thanks! (5 Replies)
Discussion started by: evelibertine
5 Replies
8. UNIX for Dummies Questions & Answers
Hi,
I am trying to extract lines from a text file given a text file containing line numbers to be extracted from the first file. How do I go about doing this? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies
9. Shell Programming and Scripting
Hello,
I have a file ff.txt that looks as follows
*ABNA.txt
356
24
36
112
*AC24.txt
457
458
321
2
ABNA.txt and AC24.txt are the files in the folder named foo1. Based on the numbers in the ff.txt file, I want to extract the lines from the corresponding files in the foo1 folder and... (2 Replies)
Discussion started by: mohamad
2 Replies
10. Shell Programming and Scripting
Hi
I have a text file named main.txt with 10,000 lines. I have another file with a list of line numbers (around 1000) of the lines to be deleted from main.txt file.
I tried with sed but it removes only a range of line numbers.
Thanks for any help!! (1 Reply)
Discussion started by: prvnrk
1 Replies
lines(3U) InterViews Reference Manual lines(3U)
NAME
Point, Line, MultiLine, S_MultiLine, SF_MultiLine - structured graphics classes for points, lines, and open polygons
SYNOPSIS
#include <Unidraw/Graphic/lines.h>
DESCRIPTION
Point and Line are subclasses of Graphic that draw a point and a line, respectively. MultiLine is a Vertices subclass that serves as an
abstract base class for open polygons: S_MultiLine is a MultiLine subclass for stroked open polygons, while SF_MultiLine is a stroked-
filled open polygon. Point, Line, and S_MultiLine store a PSBrush, while SF_MultiLine also stores a PSPattern.
POINT PUBLIC OPERATIONS
Point(Coord x, Cord y, Graphic* = nil)
Construct a Point object, optionally supplying a graphic from which to obtain an initial set of graphics state.
void GetOriginal(Coord&, Coord&)
Return the coordinates supplied in the constructor.
LINE PUBLIC OPERATIONS
Line(Coord x0, Cord y0, Coord x1, Coord y1, Graphic* = nil)
Construct a Line object, optionally supplying a graphic from which to obtain an initial set of graphics state.
void GetOriginal(Coord& x0, Coord& y0, Coord& x1, Coord& y1)
Return the line's endpoints as supplied in the constructor.
MULTILINE PROTECTED OPERATIONS
MultiLine(Coord* x, Coord* y, int count, Graphic* = nil)
MultiLine's constructor is protected to prevent instantiation of the abstract base class. The parameters are passed directly to the
Vertices constructor.
S_MULTILINE PUBLIC OPERATIONS
S_MultiLine(Coord* x, Coord* y, int count, Graphic* = nil)
Construct an S_MultiLine object, optionally supplying a graphic from which to obtain an initial set of graphics state.
SF_MULTILINE PUBLIC OPERATIONS
SF_MultiLine(Coord* x, Coord* y, int count, Graphic* = nil)
Construct an SF_MultiLine object, optionally supplying a graphic from which to obtain an initial set of graphics state.
SEE ALSO
Graphic(3U), Vertices(3U), pspaint(3U)
Unidraw 2 February 1991 lines(3U)