Sponsored Content
Full Discussion: Extract a block of text??
Top Forums Shell Programming and Scripting Extract a block of text?? Post 302490742 by marcozd on Tuesday 25th of January 2011 03:12:08 PM
Old 01-25-2011
Quote:
Originally Posted by citaylor
Ok, I can do the first thing...
Code:
 awk '{ if($0 ~ /EQUILIBRIUM GEOMETRY LOCATED/) { while($0 !~ /^\S*$/ && getline) { print $0; } } }' filename.txt

However I dont understand what you mean by "each of the columns of text should be seperated"....by what ? tabs, spaces (justified ?), commas ?

Cheers...

Hi

Thanks very much for your reply but it doesn't seem to work for me.

Nothing happens when I type in this line of code. The sed version doesn't do anything either.

Thanks though

---------- Post updated at 03:12 PM ---------- Previous update was at 03:03 PM ----------

Quote:
Originally Posted by Perderabo
A perl solution that includes some column spacing:
Code:
$
$ cat form
#! /usr/bin/perl -wn
BEGIN {$state="skip";};
/^-+$/           and do {$state="proc"; print; next LINE};
/EQUIL/          and do {print "NOW COPY\n";$state="copy";};
$state eq "skip" and do {next LINE;};
/^\s*$/          and do {last LINE;};
$state eq "copy" and do {print ; next LINE;};
$state eq "proc" and do { printf "%-10s   %6s  %16s %16s %16s\n", split(" ", $_);};
$
$
$
$ ./form < datafile | head
NOW COPY
***** EQUILIBRIUM GEOMETRY LOCATED *****
COORDINATES OF ALL ATOMS ARE (ANGS)
ATOM CHARGE X Y Z
------------------------------------------------------------
MOLYBDENUM     42.0      5.9067578125     5.0087332497    17.4699146400
SULFUR         16.0      7.9742837782     3.7588015097    17.3910898169
SULFUR         16.0      5.0973219622     3.0091611327    16.3724427108
SULFUR         16.0      3.8536412225     4.7600928861    18.7261323168
SULFUR         16.0      6.7241053728     5.6252659948    19.6631739883
$


How do I use this? What part do I place in the shell script to make this usable?
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

extract block in file

I need to extract a particular block from a file whose locations are not known but the only identity is a word. For example in a file I have ABC asdklf asdfk FGH dfdfg asdlfk asdfl ... JHK (5 Replies)
Discussion started by: sskb
5 Replies

2. Programming

c program to extract text between two delimiters from some text file

needa c program to extract text between two delimiters from some text file. and then storing them in to diffrent variables ? text file like 0: abc.txt ========= aaaaaa|11111111|sssssssssss|333333|ddddddddd|34343454564|asass aaaaaa|11111111|sssssssssss|333333|ddddddddd|34343454564|asass... (7 Replies)
Discussion started by: kukretiabhi13
7 Replies

3. Shell Programming and Scripting

Extract particular text

I executed a following sed command => echo "a/b/c/d/e/f/g/h" | sed 's/\/*$//g' a/b/c/d/e/f/g Now what if I want to extract "g" from "a/b/c/d/e/f/g/h" . That is second last string using SED. (4 Replies)
Discussion started by: Shell_Learner
4 Replies

4. Shell Programming and Scripting

Extract block of data and the error reason too. So so urgent

Hi , this is my first enty in our forum. Problem scenario: Using informatica tool am loding records from source DB to target DB. While loading some records getting rejected due to some reason. Informatica will capture those rejected records in session log file.now the session log ll be... (2 Replies)
Discussion started by: Gopal_Engg
2 Replies

5. Shell Programming and Scripting

Extract value from a text

Hi all, my problem is extract a value from a text, i mean, I have this text: > ala Nr of active alarms are: 16 ================================================================================================ Sever Specific Problem Cause Mo-Reference... (15 Replies)
Discussion started by: marimovo
15 Replies

6. Shell Programming and Scripting

Extract selective block from XML file

Hi, There's an xml file produced from a front-end tool as shown below: <INPUT DATABASE ="ORACLE" DBNAME ="UNIX" NAME ="FACT_TABLE" OWNERNAME ="DIPS"> <INPUTFIELD DATATYPE ="double" DEFAULTVALUE ="" DESCRIPTION ="" NAME ="STORE_KEY" PICTURETEXT ="" PORTTYPE ="INPUT" PRECISION ="15" SCALE... (6 Replies)
Discussion started by: dips_ag
6 Replies

7. Shell Programming and Scripting

[Awk] Extract block of with a particular pattern

Hi, I have some CVS log files, which are divided into blocks. Each block has many fields of information and I want to extract those blocks with a pattern. Here is the sample input. RCS file: /cvsroot/eclipse/org.eclipse.debug.core/core/org/eclipse/debug/core/DebugPlugin.java,v head: 1.174... (7 Replies)
Discussion started by: sandeepk1611
7 Replies

8. Shell Programming and Scripting

How to extract block from a file?

I have siebel log file as following EventContext ....... 123 ....... SELECT ... .. EventConext <---- Question 1 , I should get this line 345 ...... SELECT <----- Question 2 , print this line Test..... <----- Question 2 , print this line .... <----- Question 2 , print... (5 Replies)
Discussion started by: ran123
5 Replies

9. Shell Programming and Scripting

Grepping text block by block by using for loop

Hei buddies, Need ur help once again. I have a file which has bunch of lines which starts from a fixed pattern and ends with another fixed pattern. I want to make use of these fixed starting and ending patterns to select the bunch, one at a time. The input file is as follows. Hi welcome... (12 Replies)
Discussion started by: anushree.a
12 Replies

10. Shell Programming and Scripting

Extract a block of text

Hello all, I am working on a script which should parse a large file called input.txt which contains table definitions, index definitions and comments like these ones: ------------------------------------------------ -- DDL Statements for table "CMWSYS"."CMWD_TEC_SUIVI_TRT"... (12 Replies)
Discussion started by: kiki_riki_miki
12 Replies
charnames(3pm)						 Perl Programmers Reference Guide					    charnames(3pm)

NAME
charnames - define character names for "N{named}" string literal escapes SYNOPSIS
use charnames ':full'; print "N{GREEK SMALL LETTER SIGMA} is called sigma. "; use charnames ':short'; print "N{greek:Sigma} is an upper-case sigma. "; use charnames qw(cyrillic greek); print "N{sigma} is Greek sigma, and N{be} is Cyrillic b. "; use charnames ":full", ":alias" => { e_ACUTE => "LATIN SMALL LETTER E WITH ACUTE", }; print "N{e_ACUTE} is a small letter e with an acute. "; use charnames (); print charnames::viacode(0x1234); # prints "ETHIOPIC SYLLABLE SEE" printf "%04X", charnames::vianame("GOTHIC LETTER AHSA"); # prints "10330" DESCRIPTION
Pragma "use charnames" supports arguments ":full", ":short", script names and customized aliases. If ":full" is present, for expansion of "N{CHARNAME}", the string "CHARNAME" is first looked up in the list of standard Unicode character names. If ":short" is present, and "CHARNAME" has the form "SCRIPT:CNAME", then "CNAME" is looked up as a letter in script "SCRIPT". If pragma "use charnames" is used with script name arguments, then for "N{CHARNAME}" the name "CHARNAME" is looked up as a letter in the given scripts (in the specified order). Customized aliases are explained in "CUSTOM ALIASES". For lookup of "CHARNAME" inside a given script "SCRIPTNAME" this pragma looks for the names SCRIPTNAME CAPITAL LETTER CHARNAME SCRIPTNAME SMALL LETTER CHARNAME SCRIPTNAME LETTER CHARNAME in the table of standard Unicode names. If "CHARNAME" is lowercase, then the "CAPITAL" variant is ignored, otherwise the "SMALL" variant is ignored. Note that "N{...}" is compile-time, it's a special form of string constant used inside double-quoted strings: in other words, you cannot use variables inside the "N{...}". If you want similar run-time functionality, use charnames::vianame(). For the C0 and C1 control characters (U+0000..U+001F, U+0080..U+009F) as of Unicode 3.1, there are no official Unicode names but you can use instead the ISO 6429 names (LINE FEED, ESCAPE, and so forth). In Unicode 3.2 (as of Perl 5.8) some naming changes take place ISO 6429 has been updated, see "ALIASES". Also note that the U+UU80, U+0081, U+0084, and U+0099 do not have names even in ISO 6429. Since the Unicode standard uses "U+HHHH", so can you: "N{U+263a}" is the Unicode smiley face, or "N{WHITE SMILING FACE}". ALIASES
A few aliases have been defined for convenience: instead of having to use the official names LINE FEED (LF) FORM FEED (FF) CARRIAGE RETURN (CR) NEXT LINE (NEL) (yes, with parentheses) one can use LINE FEED FORM FEED CARRIAGE RETURN NEXT LINE LF FF CR NEL One can also use BYTE ORDER MARK BOM and ZWNJ ZWJ for ZERO WIDTH NON-JOINER and ZERO WIDTH JOINER. For backward compatibility one can use the old names for certain C0 and C1 controls old new HORIZONTAL TABULATION CHARACTER TABULATION VERTICAL TABULATION LINE TABULATION FILE SEPARATOR INFORMATION SEPARATOR FOUR GROUP SEPARATOR INFORMATION SEPARATOR THREE RECORD SEPARATOR INFORMATION SEPARATOR TWO UNIT SEPARATOR INFORMATION SEPARATOR ONE PARTIAL LINE DOWN PARTIAL LINE FORWARD PARTIAL LINE UP PARTIAL LINE BACKWARD but the old names in addition to giving the character will also give a warning about being deprecated. CUSTOM ALIASES
This version of charnames supports three mechanisms of adding local or customized aliases to standard Unicode naming conventions (:full). Note that an alias should not be something that is a legal curly brace-enclosed quantifier (see "QUANTIFIERS" in perlreref). For example "N{123}" means to match 123 non-newline characters, and is not treated as an alias. Aliases are discouraged from beginning with anything other than an alphabetic character and from containing anything other than alphanumerics, spaces, dashes, colons, parentheses, and underscores. Currently they must be ASCII. Anonymous hashes use charnames ":full", ":alias" => { e_ACUTE => "LATIN SMALL LETTER E WITH ACUTE", }; my $str = "N{e_ACUTE}"; Alias file use charnames ":full", ":alias" => "pro"; will try to read "unicore/pro_alias.pl" from the @INC path. This file should return a list in plain perl: ( A_GRAVE => "LATIN CAPITAL LETTER A WITH GRAVE", A_CIRCUM => "LATIN CAPITAL LETTER A WITH CIRCUMFLEX", A_DIAERES => "LATIN CAPITAL LETTER A WITH DIAERESIS", A_TILDE => "LATIN CAPITAL LETTER A WITH TILDE", A_BREVE => "LATIN CAPITAL LETTER A WITH BREVE", A_RING => "LATIN CAPITAL LETTER A WITH RING ABOVE", A_MACRON => "LATIN CAPITAL LETTER A WITH MACRON", ); Alias shortcut use charnames ":alias" => ":pro"; works exactly the same as the alias pairs, only this time, ":full" is inserted automatically as first argument (if no other argument is given). charnames::viacode(code) Returns the full name of the character indicated by the numeric code. The example print charnames::viacode(0x2722); prints "FOUR TEARDROP-SPOKED ASTERISK". Returns undef if no name is known for the code. This works only for the standard names, and does not yet apply to custom translators. Notice that the name returned for of U+FEFF is "ZERO WIDTH NO-BREAK SPACE", not "BYTE ORDER MARK". charnames::vianame(name) Returns the code point indicated by the name. The example printf "%04X", charnames::vianame("FOUR TEARDROP-SPOKED ASTERISK"); prints "2722". Returns undef if the name is unknown. This works only for the standard names, and does not yet apply to custom translators. CUSTOM TRANSLATORS
The mechanism of translation of "N{...}" escapes is general and not hardwired into charnames.pm. A module can install custom translations (inside the scope which "use"s the module) with the following magic incantation: sub import { shift; $^H{charnames} = &translator; } Here translator() is a subroutine which takes "CHARNAME" as an argument, and returns text to insert into the string instead of the "N{CHARNAME}" escape. Since the text to insert should be different in "bytes" mode and out of it, the function should check the current state of "bytes"-flag as in: use bytes (); # for $bytes::hint_bits sub translator { if ($^H & $bytes::hint_bits) { return bytes_translator(@_); } else { return utf8_translator(@_); } } See "CUSTOM ALIASES" above for restrictions on "CHARNAME". ILLEGAL CHARACTERS
If you ask by name for a character that does not exist, a warning is given and the Unicode replacement character "x{FFFD}" is returned. If you ask by code for a character that is unassigned, no warning is given and "undef" is returned. (Though if you ask for a code point past U+10FFFF you do get a warning.) See "BUGS" below. BUGS
viacode should return an empty string for unassigned in-range Unicode code points, as that is their correct current name. viacode(0) doesn't return "NULL", but "undef" vianame returns a chr if the input name is of the form "U+...", and an ord otherwise. It is planned to change this to always return an ord. None of the functions work on almost all the Hangul syllable and CJK Unicode characters that have their code points as part of their names. Names must be ASCII characters only. Unicode standard named sequences are not recognized, such as "LATIN CAPITAL LETTER A WITH MACRON AND GRAVE" (which should mean "LATIN CAPITAL LETTER A WITH MACRON" with an additional "COMBINING GRAVE ACCENT"). Since evaluation of the translation function happens in the middle of compilation (of a string literal), the translation function should not do any "eval"s or "require"s. This restriction should be lifted in a future version of Perl. perl v5.12.1 2010-05-13 charnames(3pm)
All times are GMT -4. The time now is 07:42 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy