Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Copying Text between two unique text patterns Post 302119187 by drl on Monday 28th of May 2007 03:15:15 PM
Old 05-28-2007
Hi.

For the sample data file "data1":
Code:
Document * of 20
Hello

=====
Document one of 20

World

=====
Document 44 of 20

Now is

=====
Document "Climatology Review" in of 20

with no Documents at the beginning of the time.

=====

I ran this script:
Code:
#!/bin/sh

# @(#) s1       Demonstrate csplit.

F=${1-data1}

csplit -k -s -z $F "/^Document.*of/" {\*}

echo
for file in xx*
do
        echo
        echo "File: $file"
        head -3 $file |
        cat -n
done

exit 0

To produce this:
Code:
% ./s1


File: xx00
     1  Document * of 20
     2  Hello
     3

File: xx01
     1  Document one of 20
     2
     3  World

File: xx02
     1  Document 44 of 20
     2
     3  Now is

File: xx03
     1  Document "Climatology Review" in of 20
     2
     3  with no Documents at the beginning of the time.

This assumes that the lines "=====" are visual sugar ... cheers, drl
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

extracting unique lines from text file

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. Shell Programming and Scripting

Extracting Text Between Two Unique Lines

Hi all! Im trying to extract a portion of text from a file and put it into a new file. I need all the lines between <Placement> and </Placement> including the Placemark lines themselves. Is there a way to extract all instances of these and not just the first one found? I've tried using sed and... (4 Replies)
Discussion started by: Grizzly
4 Replies

3. Shell Programming and Scripting

Extracting several lines of text after a unique string

I'm attempting to write a script to identify users who have sudo access on a server. I only want to extract the ID's of the sudo users after a unique line of text. The list of sudo users goes to the EOF so I only need the script to start after the unique line of text. I already have a script to... (1 Reply)
Discussion started by: bouncer
1 Replies

4. UNIX for Advanced & Expert Users

Vi copying text

Is there a trick for copying from something like a powerpoint into vi? Every time I try to copy text from something like a powerpoint to vi my spacing gets messed up. I think it has something to do with my .vimrc file. When I renamed it was able to copy it in just fine so can someone please... (2 Replies)
Discussion started by: cokedude
2 Replies

5. UNIX for Dummies Questions & Answers

Copying text from Windows to AIX - missing text?

Hi All, I'm hoping this is an easy question, but I'm having a weird problem trying to simply copy and paste text from MS Windows (XP) Notepad and then pasting into vi or vim in AIX. When I type "oslevel" I get "5.3.0.0". The problem is that once the text is pasted, there are sections of text... (2 Replies)
Discussion started by: PlainInverted
2 Replies

6. Shell Programming and Scripting

Replacing text between two patterns

I would like to replace ], with ]]], between /* SECTION2-BEGIN */ and /* SECTION2-END */ in my file. My file contains the following information: /* SECTION1-BEGIN */ , /* SECTION1-END */ /* SECTION2-BEGIN */ , /* SECTION2-END */ /*... (5 Replies)
Discussion started by: azdps
5 Replies

7. Shell Programming and Scripting

Need to extract text repetitively between two patterns

Hi All, I want to extract the text between some pattern which occurs repeatedly in a file. For example my input is like, /home/..... ..........java:25: cannot find symbol ............ /home/...... /home/....... I want to display... (2 Replies)
Discussion started by: Vignesh58
2 Replies

8. Shell Programming and Scripting

Find patterns and filter the text

I need to filter the text in between two patterns and output that to a different file. Please help me how to do it. Ex: ............. <some random text> ............. Pattern_1 <Few lines that need to be output to different file> Pattern_2 ................ ............... <more text in... (4 Replies)
Discussion started by: metturr
4 Replies

9. Shell Programming and Scripting

Command for non-unique text

awk -F "" '/<TestName>|<testname>|<Offerer>|<offerer>|<Line1>|<line1>|<City>|<city>|<State>|<state>/ {print $2, $3}' OFS='\t' UBE3A.xml > UBE3A.txt Is it possible to use the code above to search for a pattern that is non-unique? For example, if I wanted to capture the<MethodList>|<string>... (6 Replies)
Discussion started by: cmccabe
6 Replies

10. Shell Programming and Scripting

awk to print unique text in field

I am trying to use awk to print the unique entries in $2 So in the example below there are 3 lines but 2 of the lines match in $2 so only one is used in the output. File.txt chr17:29667512-29667673 NF1:exon.1;NF1:exon.2;NF1:exon.38;NF1:exon.4;NF1:exon.46;NF1:exon.47 703.807... (5 Replies)
Discussion started by: cmccabe
5 Replies
snscan,v0.3.8(8)					      System Manager's Manual						  snscan,v0.3.8(8)

NAME
snscan - display information on articles in the spool sncat - display articles in the spool sncancel - cancel articles in the spool SYNOPSIS
snscan [options] articlespec... sncat [options] articlespec... sncancel [options] articlespec... options: [-n] [-s since] [-o outputfile] DESCRIPTION
snscan displays information on all articles specified by articlespec, in the form newsgroup serial id on a line, one line per article matched. This output is suitable for feeding to snprimedb. sncat displays the articles specified by articlespec. sncancel marks articles specified by articlespec as canceled, so they become unavailable to sn programs. ARGUMENTS
articlespec defines a broad pattern for articles. It takes two mutually exclusive forms. Specify by newsgroup and serial number Here articlespec is newsgroup[:range[,range]...] where each range is serial[-[toserial]] (where toserial is greater than serial). If toserial is omitted, then all articles after serial are matched. If both serial and toserial are empty, then only the first and last articles are matched. Specify by articles message ID Here articlespec is -i id... where each id is a message ID, angle brackets optional. OPTIONS
-n This option weeds out articles that are aliases. If an article is crossposted, there will be an original copy, the others will be aliases to it. This option prevents information being displayed if it is not from the original copy. -ssince This option weeds out articles that were obtained before since. since is in the format year/month/day[:hour:minute] where each is a number. year may be 2 or 4 digits, and / and : can be any non-digit character. -ooutputfile Write output to outputfile instead of descriptor 1. Sometimes you just don't feel like using the shell. EXAMPLES
sncancel linux.lemmings:12 Cancel article 12 from linux.lemmings. snscan linux.lemmings:4,12- Display information on article 4, and also articles 12 to the most recent article, from linux.lemmings. sncat -n -s 1998/4/1 linux.lemmings Display all articles that are not aliases, and which were entered after April 1 1998, from linux.lemmings. snscan -i '123@myhost' Display information on the article whose ID is <123@myhost>, in whichever newsgroup it is found. FILES
Each articlespec or id on the command line refers to articles in the news spool located in /var/spool/sn. ENVIRONMENT VARIABLES
SNROOT If this is set and is not empty, the value is used in place of /var/spool/sn, the default news spool directory. EXIT CODES
snscan exits 0 on success, 1 on usage error, 2 on system error, and 3 on other errors. It is not an error to specify an article that does not exist, or which does not meet the since criterion. SEE ALSO
snprimedb(8) N.B. Harold Tay snscan,v0.3.8(8)
All times are GMT -4. The time now is 02:57 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy