Sponsored Content
Top Forums Shell Programming and Scripting Extract multiple occurance of strings between 2 patterns Post 302867385 by sameermohite on Thursday 24th of October 2013 06:23:44 AM
Old 10-24-2013
Hi all ..
thank you very much for prompt reply..

@krishmaths - your answer suits my requirement perfectly
@skrynesaver- perl also works but it shows output in separate line.
@Don cragon - It works only when number of columns is known

---------- Post updated at 03:53 PM ---------- Previous update was at 03:52 PM ----------

thanks Akshay.. works perfectly
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to extract multiple strings from a line

Hi I have the following requirement. i have the following line from a log file one : two : Three : four : five : six : seven : eight :nine :ten Now can you pls help what i should do to get only the following output from the above line two : five : six : seven : Eight appreciate your... (3 Replies)
Discussion started by: vin_eme
3 Replies

2. Shell Programming and Scripting

Count occurance of multiple strings using grep command

How to grep multiple string occurance in input file using single grep command? I have below input file with many IDP, RRBE messages. Out put should have count of each messages. I have used below command but it is not working grep -cH "(sent IDP Request)(Recv RRBCSM)" *.txt ... (5 Replies)
Discussion started by: sushmab82
5 Replies

3. Shell Programming and Scripting

extract till occurance of a string

hi , i have an xml that comes in a single, the entire xml file is read as a single line when i open in edit plus or unix. i need to amend the contents of this xml file. below is the extract from the file <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"... (5 Replies)
Discussion started by: sais
5 Replies

4. Shell Programming and Scripting

Extract strings from multiple lines into one file -

input file Desired csv output gc_type, date/time, milli secs af, Mar 17 13:09:04 2011, 144.596 af, Mar 20 00:37:37 2011, 144.242 af, ar 20 21:30:59 2011, 108.518 Hi All, Any help in acheiving the above would be appreciated. I would like to parse through lines within one file and... (5 Replies)
Discussion started by: satish.vampire
5 Replies

5. Shell Programming and Scripting

Extract strings from multiple lines into one csv file

Hi all, Please go through my requirement. I have a log file in the location /opt/WebSphere61/AppServer/profiles/EMQbatchprofile/logs/EMQbatch This file contains the follwing pattern data <af type="tenured" id="42" timestamp="May 14 13:44:13 2011" intervalms="955.624"> <minimum... (8 Replies)
Discussion started by: satish.vampire
8 Replies

6. Shell Programming and Scripting

awk? extract quoted "" strings from multiple lines.

I am trying to extract multiple strings from snmp-mib files like below. ----- $ cat IF-MIB.mib <snip> linkDown NOTIFICATION-TYPE OBJECTS { ifIndex, ifAdminStatus, ifOperStatus } STATUS current DESCRIPTION "A linkDown trap signifies that the SNMP entity, acting in... (5 Replies)
Discussion started by: genzo
5 Replies

7. Shell Programming and Scripting

awk extract strings matching multiple patterns

Hi, I wasn't quite sure how to title this one! Here goes: I have some already partially parsed log files, which I now need to extract info from. Because of the way they are originally and the fact they have been partially processed already, I can't make any assumptions on the number of... (8 Replies)
Discussion started by: chrissycc
8 Replies

8. Shell Programming and Scripting

Extract multiple strings from line

Hello I have an output that has a string between quotes and another between square brackets on the same line. I need to extract these 2 strings Example line Device "nrst3a" attributes=(0x4) RAW SERIAL_NUMBER=SNL2 Output should look like nrst3a VD073AV1443BVW00083 I was trying with sed... (3 Replies)
Discussion started by: bombcan
3 Replies

9. UNIX for Beginners Questions & Answers

Extract only first occurance

Hi All, From the below file. I need to get only the first occurrence and print. I tried to do it in separate grep not coming as expected Original file 11001;1213;304;;;;;;;111020677.64;;;;;;;;;;;;;;;;;;;;;;;;;; 11001;1214;304;;;;;;;102376462.96;;;;;;;;;;;;;;;;;;;;;;;;;;... (5 Replies)
Discussion started by: arunkumar_mca
5 Replies

10. UNIX for Beginners Questions & Answers

Match patterns between two files and extract certain range of strings

Hi, I need help to match patterns from between two different files and extract region of strings. inputfile1.fa >l-WR24-1:1 GCCGGCGTCGCGGTTGCTCGCGCTCTGGGCGCTGGCGGCTGTGGCTCTACCCGGCTCCGG GGCGGAGGGCGACGGCGGGTGGTGAGCGGCCCGGGAGGGGCCGGGCGGTGGGGTCACGTG... (4 Replies)
Discussion started by: bunny_merah19
4 Replies
extract(1)						      General Commands Manual							extract(1)

NAME
extract - interactive string extract and replace SYNOPSIS
extract [-i ignorefile] [-m prefix] [-n] [-p patternfile] [-s string] [-u] source-program... OPTIONS
Ignore text strings specified in ignorefile. By default, the extract command searches for ignorefile in the current working directory, your home directory, and /usr/lib/nls. If you omit the -i option, extract recognizes all strings specified in the patterns file. Add prefix to message numbers in the out- put source program and source message catalog. You can use this prefix as a mnemonic. You must process source message catalogs that contain message number prefixes using the mkcatdefs command. Create a new source message catalog for each input source pro- gram. By default, if you specify more than one input source program on the extract command line, the command creates one source message catalog for all the input source programs. Use patternfile to match strings in the input source program. By default, the command searches for the pattern file in the current directory, your home directory, and /usr/lib/nls. If you omit the -p option, the extract command uses a default patterns file that is stored in /usr/lib/nls/patterns. Write string at the top of the source message catalog. If you omit the -s option, extract uses the string specified in the $CATHEAD section of the patterns file. Use a message file produced by a previous run of strextract. This file contains details of all the strings which matched the pattern file along with file offsets and line numbers. By default strextract is run and its output is used to drive extract. DESCRIPTION
The extract command interactively extracts text strings from source programs. The extract command replaces the strings it extracts with calls to the catgets function. The command also writes the string it extracts to a source message catalog. You use this command to replace hard-coded messages in your program source file with calls to the catgets command and create a source message catalog. At run time, the program reads the message text from the message catalog. By storing messages in a message catalog, instead of in your program, you allow the text of messages to be translated to a new language or modified without the source program being changed. In the source-program argument, you name one or more source programs from which you want messages extracted. The extract command does not extract messages from source programs included using the #include directive. Therefore, you might want to name a source program and all the source programs it includes on a single extract command line. You can create a patterns file (as specified by patternfile) to control how the extract command extracts and replaces text. The patterns file is divided into several sections, each of which is identified by a keyword. The keyword must start at the beginning of a new line, and its first character must be a dollar sign ($). Following the identifier, you specify a number of patterns. Each pattern begins on a new line and follows the regular expression syntax you use in the regexp routine. For more information on the patterns file, see pat- terns(4)and for more information on the regexp routine, see regexp(3). In addition to the patterns file, you can create a file that indicates strings that extract ignores. Each line in this ignore file con- tains a single string to be ignored that follows the syntax of the regexp routine. When you invoke the extract command, it reads the patterns file and the file that contains strings it ignores. You can specify a patterns file and an ignore file on the extract command line. Otherwise, the extract command matches all strings and uses a default patterns file. When you run extract, it displays three windows on your terminal. The first window contains the program source code. The string that matches a string in the patterns file is displayed in reverse video. The second window displays the contents of the source message catalog that the extract command is creating. The third window contains a list of the commands that are available. The extract command displays the current command in reverse video. You can execute the current command by pressing the RETURN key. Select another command by typing the first letter in the command name and pressing the RETURN key. The extract command is not sensitive to the case of letters, so you can use uppercase or lowercase letters to issue commands. You can use the following commands to control how extract treats the string displayed in the first window: Extract the string into the cat- alog file and rewrite the source using the rewrite string in the patterns file. If the string has been encountered previously, rewrite the source program using the same message number as before. The extract command need not add the message to the source message catalog again, so this command saves space in catalogs. Ignore this and all subsequent occurrences of this string during this interactive session. This command does not add the string to the ignore file. Pass by (ignore) this occurrence of this particular string. Ignore this and all sub- sequent occurrences of this string during this interactive session. Add the string to the ignore file. Add the comment you enter to the source message catalog. The extract command prompts you to be sure the comment you entered is correct. You answer the prompt by typing "y," "n," or "q," without pressing the RETURN key. Quit from the interactive session. The extract command prompts you to be sure you want to quit. Answer "y" or "n" to the prompt, without pressing the return key. The output files that extract creates up to this point are not removed by this command. However, the files contain only the result of the string extractions that occurred before you issued the QUIT command. Display a description of all the extract commands. The extract command creates two files in your current working directory. The command creates a new version of the source program that con- tains calls to the catgets function, instead of hard-coded messages. The new version of the source program has the same name as the input source program, with the prefix nl_. For example, if the input source program is named update.c, the output source program is named nl_update.c. In addition to a new source program, the extract command creates a source message catalog. The source message catalog contains the text for each message extracted from your input source program. The extract command names the file by appending to the name of the input source program. For example, the source message catalog for the update.c source program is named update.msg. You can use the source message cat- alog as input to the gencat command. RESTRICTIONS
Given the current syntax of the patterns file, you cannot cause extract to ignore strings in comments that are longer than one line. You can specify only one rewrite string for all classes of pattern matches. The extract command does not extract strings from files you include with the #include directive. You must run the extract commands on these files separately. Your terminal screen must contain at least 80 columns and 24 lines for extract to display its three windows. The extract command does not recognize strings that extend beyond one line. EXAMPLES
The following example shows the commands you issue to run the extract command, create a message catalog from the source message catalog, and compile the output source program: % extract -i newignore -p c_patterns remove.c % gencat remove.cat remove.msg % vi nl_remove.c % cc nl_remove.c In this example, the extract command uses the newignore file to determine which strings to ignore. The command uses the c_patterns file to determines which strings to match. The input source program is named remove.c. In response to this command, extract creates the source message catalog remove.msg and the output source program nl_remove.c. You must edit nl_remove.c to include the appropriate catopen and catclose function calls. The gencat command creates a message catalog and the cc command creates an executable program. SEE ALSO
gencat(1), mkcatdefs(1), strextract(1), strmerge(1), catopen(3), catgets(3), regexp(3), patterns(4) Writing Software for the International Market extract(1)
All times are GMT -4. The time now is 06:10 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy