Sponsored Content
Full Discussion: Extract a string from a file
Top Forums Shell Programming and Scripting Extract a string from a file Post 302873115 by nitinupadhyaya8 on Monday 11th of November 2013 07:33:37 AM
Old 11-11-2013
Code:
awk -F"(" '{print $2}' file | awk -F")" '{print $1}'
 
awk -F"(" '{print $2}' file | sed 's/)//g'

This would work only if the content of the file is as below

Code:
SYSLIB(SANJ)
INCLUDE SYSLIB(BIS)


Last edited by Scott; 11-11-2013 at 08:38 AM.. Reason: Code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract a string from a file

Input File: ===================================== "Server1" srvgrp="group1" srvid=10 CLOPT="-A -r -e /path/logfile -o /path/stdout" VAR1=0666 VAR2=N VAR3=0666 MIN=3 VAR4=4 VAR5=N VAR6=FASTPATH VAR7=5 VAR8=86400 VAR9=Y ... (20 Replies)
Discussion started by: kaustubh137
20 Replies

2. Shell Programming and Scripting

Search for string in a file and extract another string to a variable

Hi, guys. I have one question: I need to search for a string in a file, and then extract another string from the file and assign it to a variable. For example: the contents of the file (group) is below: ... ftp:x:23: mail:x:34 ... testing:x:2001 sales:x:2002 development:x:2003 ...... (6 Replies)
Discussion started by: daikeyang
6 Replies

3. Shell Programming and Scripting

Find a string and extract a value from a file

I have a file where a line has the following form: n0=7.00 !Central density and I want to extract the value 7.00. I used to do this with the order below, which finds the string "n0" and take the rest of the line parting from the separator "=", but the comment "Central density..."... (7 Replies)
Discussion started by: josegr
7 Replies

4. Shell Programming and Scripting

Extract string from a file & write to a new file (Perl)

Hi, This is the first time playing around with perl and need some help. Assuming if i have a line of text that looks like this: Date/Time=Nov 18 17:12:11;Device Name=192.168.1.1;Device IP=192.168.1.1;Device Class=IDS;Source IP=155.212.212.111;Source Name=UNKNOWN;Source Port=1679... (3 Replies)
Discussion started by: LuckyGuy
3 Replies

5. Shell Programming and Scripting

Extract a string from file

Below are the content of my file and i need to extract the 6 digit numbers after the word barcode, how can i do this? for example i need to extract 004119,004275,004030 to a new file. Logically move media ID 004119 (barcode 004119) from standalone to slot 18. Logically move media ID 004275... (9 Replies)
Discussion started by: shehzad_m
9 Replies

6. Shell Programming and Scripting

awk extract a string from a file

Hi, I have a file which has thousand of lines with lines starting with And I want to extract and show to user only the below string from all the lines Please note note that the above string is a time stamp and it would be different on all the lines. Please tell me how to extract... (8 Replies)
Discussion started by: jredx
8 Replies

7. Shell Programming and Scripting

Extract a string between 2 ref string from a file

Hi, May i ask if someone share some command for extracting a string between 2 ref string in a txt file My objective: i had a file with multiple lines and wants only to extract the string "watch?v=IbkAXOmEHpY" or "watch?v=<11 random character>", when i used "grep 'watch?=*' i got a results per... (4 Replies)
Discussion started by: jao_madn
4 Replies

8. Shell Programming and Scripting

extract string from file name between two underscores

Hi, Here is my question, I need to extract string between two underscores from the filename for example, filename is atmos_8xdaily_instant_300x300_1_12.nc what I want to extract is 300x300. There are many such files in my directory, so I guess the code should be like: for file... (7 Replies)
Discussion started by: 1988PF
7 Replies

9. Shell Programming and Scripting

Extract a specific string from a file

Hi, I have a file whose contents are as follows. 2013-03-08/15:09:20.134 INFO 00000000-00000000 0034 09700400 CON_IN SessionID:ED5E1400-4805-85E2-17B2-5BE45684886A Connection ID:ED5E1400-4805-68F1-BB1D-F06496BCF910 TO:<sip:51234999@10.239.94.146:5060 FROM:<sip:9302280716@97.208.31.7:51024... (2 Replies)
Discussion started by: SunilB2011
2 Replies

10. Shell Programming and Scripting

Need to extract a String from log file

Hi i am having a logfile which contain lot of entires, but i need extract a word after if i found a line that contains a particular string as "ENROLLMENT_EXCEPTION - Exception". please help me in getting a script to do this. Regards C. Suresh (5 Replies)
Discussion started by: sumeeva1907
5 Replies
Template::Manual::Syntax(3)				User Contributed Perl Documentation			       Template::Manual::Syntax(3)

NAME
Template::Manual::Syntax - Directive syntax, structure and semantics Tag Styles By default, template directives are embedded within the character sequences "[%" and "%]". [% PROCESS header %] <h1>Hello World!</h1> <a href="[% page.next %]"><img src="[% icon.next %].gif"></a> [% PROCESS footer %] You can change the tag characters using the "START_TAG", "END_TAG" and "TAG_STYLE" configuration options. You can also use the "TAGS" directive to define a new tag style for the current template file. You can also set the "INTERPOLATE" option to allow simple variable references to be embedded directly in templates, prefixed by a "$". # INTERPOLATE = 0 <td>[% name %]</td> <td>[% email %]</td> # INTERPOLATE = 1 <td>$name</td> <td>$email</td> Directives may be embedded anywhere in a line of text and can be split across several lines. Insignificant whitespace is generally ignored within the directive. [% INCLUDE header title = 'Hello World' bgcol = '#ffffff' %] [%INCLUDE menu align='right'%] Name: [% name %] ([%id%]) Comments The "#" character is used to indicate comments within a directive. When placed immediately inside the opening directive tag, it causes the entire directive to be ignored. [%# this entire directive is ignored no matter how many lines it wraps onto %] In any other position, it causes the remainder of the current line to be treated as a comment. [% # this is a comment theta = 20 # so is this rho = 30 # <aol>me too!</aol> %] Chomping Whitespace You can add "-" or "+" to the immediate start or end of a directive tag to control the whitespace chomping options. See the "PRE_CHOMP" and "POST_CHOMP" options for further details. [% BLOCK foo -%] # remove trailing newline This is block foo [%- END %] # remove leading newline Implicit Directives: GET and SET The simplest directives are "GET" and "SET" which retrieve and update variable values respectively. The "GET" and "SET" keywords are actually optional as the parser is smart enough to see them for what they really are (but note the caveat below on using side-effect notation). Thus, you'll generally see: [% SET foo = 10 %] [% GET foo %] written as: [% foo = 10 %] [% foo %] You can also express simple logical statements as implicit "GET" directives: [% title or template.title or 'Default Title' %] [% mode == 'graphics' ? "Graphics Mode Enabled" : "Text Mode" %] All other directives should start with a keyword specified in UPPER CASE (but see the "ANYCASE" option). All directives keywords are in UPPER CASE to make them visually distinctive and to distinguish them from variables of the same name but different case. It is perfectly valid, for example, to define a variable called "stop" which is entirely separate from the "STOP" directive. [% stop = 'Clackett Lane Bus Depot' %] The bus will next stop at [% stop %] # variable [% STOP %] # directive Block Directives Directives such as "FOREACH", "WHILE", "BLOCK", "FILTER", etc., mark the start of a block which may contain text or other directives up to the matching "END" directive. Blocks may be nested indefinitely. The "IF", "UNLESS", "ELSIF" and "ELSE" directives also define blocks and may be grouped together in the usual manner. [% FOREACH item = [ 'foo' 'bar' 'baz' ] %] * Item: [% item %] [% END %] [% BLOCK footer %] Copyright 2000 [% me %] [% INCLUDE company/logo %] [% END %] [% IF foo %] [% FOREACH thing = foo.things %] [% thing %] [% END %] [% ELSIF bar %] [% INCLUDE barinfo %] [% ELSE %] do nothing... [% END %] Block directives can also be used in a convenient side-effect notation. [% INCLUDE userinfo FOREACH user = userlist %] [% INCLUDE debugtxt msg="file: $error.info" IF debugging %] [% "Danger Will Robinson" IF atrisk %] versus: [% FOREACH user = userlist %] [% INCLUDE userinfo %] [% END %] [% IF debugging %] [% INCLUDE debugtxt msg="file: $error.info" %] [% END %] [% IF atrisk %] Danger Will Robinson [% END %] Capturing Block Output The output of a directive can be captured by simply assigning the directive to a variable. [% headtext = PROCESS header title="Hello World" %] [% people = PROCESS userinfo FOREACH user = userlist %] This can be used in conjunction with the "BLOCK" directive for defining large blocks of text or other content. [% poem = BLOCK %] The boy stood on the burning deck, His fleece was white as snow. A rolling stone gathers no moss, And Keith is sure to follow. [% END %] Note one important caveat of using this syntax in conjunction with side-effect notation. The following directive does not behave as might be expected: [% var = 'value' IF some_condition %] # does not work In this case, the directive is interpreted as (spacing added for clarity) [% var = IF some_condition %] value [% END %] rather than [% IF some_condition %] [% var = 'value' %] [% END %] The variable is assigned the output of the "IF" block which returns 'value' if true, but nothing if false. In other words, the following directive will always cause 'var' to be cleared. [% var = 'value' IF 0 %] To achieve the expected behaviour, the directive should be written as: [% SET var = 'value' IF some_condition %] Chaining Filters Multiple "FILTER" directives can be chained together in sequence. They are called in the order defined, piping the output of one into the input of the next. [% PROCESS somefile FILTER truncate(100) FILTER html %] The pipe character, "|", can also be used as an alias for "FILTER". [% PROCESS somefile | truncate(100) | html %] Multiple Directive Blocks Multiple directives can be included within a single tag when delimited by semi-colons. Note however that the "TAGS" directive must always be specified in a tag by itself. [% IF title; INCLUDE header; ELSE; INCLUDE other/header title="Some Other Title"; END %] versus [% IF title %] [% INCLUDE header %] [% ELSE %] [% INCLUDE other/header title="Some Other Title" %] [% END %] perl v5.16.3 2011-12-20 Template::Manual::Syntax(3)
All times are GMT -4. The time now is 07:41 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy