Sponsored Content
Top Forums Shell Programming and Scripting Perl or Awk script to copy a part of text file. Post 302367431 by frans on Monday 2nd of November 2009 03:00:35 PM
Old 11-02-2009
What a challenge to script that in shell !
Here, i've coded something wich works
Code:
LINE="lbla bla bla jcjfd<text>what i want</text>flh%(j blablabla<text>second occurence</text>juhgfiuhf<text>third occ</text>jkhgq"
I=1
LINE=${LINE#*<text>}	# Removes all from the begining up to the first "<text>"
LINE=${LINE%</text>*}	# Removes all from the end down to the last "</text>"
while echo $LINE | grep -q "<text>"	# more than one field
do	TEXT[$I]=${LINE%%</text>*}
	LINE=${LINE#*<text>}
	(( I ++ ))
done
TEXT[$I]=${LINE%</text>*}	# for the last one
{	# To see what we've done
	N=$I
	for I in $(seq $N)
	do	echo "TEXT[$I] = ${TEXT[$I]}"
	done
}

Look if it works by you. If so it's possible to embed it in the appropriate code to parse your files.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Shell script to search for text in a file and copy file

Compete noob question.... I need a script to search through a directory and find files containing text string abcde1234 for example and then copy that file with that text string to another directory help please :eek: (9 Replies)
Discussion started by: imeadows
9 Replies

2. Shell Programming and Scripting

awk, perl Script for processing a single line text file

I need a script to process a huge single line text file: The sample of the text is: "forward_inline_item": "Inline", "options_region_Australia": "Australia", "server_event_err_msg": "There was an error attempting to save", "Token": "Yes", "family": "Family","pwd_login_tab": "Enter Your... (1 Reply)
Discussion started by: hmsadiq
1 Replies

3. Shell Programming and Scripting

shell script to take input from a text file and perform check on each servers and copy files

HI all, I want to script where all the server names will be in a text file like server1 server2 server3 . and the script should take servernames from a text file and perform copy of files if the files are not present on those servers.after which it should take next servername till the end of... (0 Replies)
Discussion started by: joseph.dmello
0 Replies

4. Shell Programming and Scripting

search needed part in text file (awk?)

Hello! I have text file: From aaa@bbb Fri Jun 1 10:04:29 2010 --____OSPHWOJQGRPHNTTXKYGR____ Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline My code '234565'. ... (2 Replies)
Discussion started by: candyme
2 Replies

5. UNIX for Dummies Questions & Answers

Copy a part of file

Hi, I want to copy text between expressions ">bcr1" and ">bcr2" to another file. Any simple solutions? Thanks (4 Replies)
Discussion started by: alpesh
4 Replies

6. UNIX for Dummies Questions & Answers

Copy the last part since the file has been updated

Input File1 constatntly running and growing in size. My Program Erorr ddmmyy hh:mm:ss My Program Error **Port 123 terminated **ID PIN 12345 Comamnd Successful Command Terminated Command Successful Command Terminated **My Program Erorr ddmmyy hh:mm:ss My Program Error **Port 345... (3 Replies)
Discussion started by: eurouno
3 Replies

7. Shell Programming and Scripting

Copy part of file between two strings to another

I am a newbie to shell scripting I have a large log file , i need to work on the part of the log file for a particular date. Is there a way to find the first occurance of the date string and last occurance of the next day date date string and move this section to a new file. to explain it... (3 Replies)
Discussion started by: swayam123
3 Replies

8. Shell Programming and Scripting

Copy a file from local host to a list of remote hosts --- perl script

Hi friends, i need to prepare a script ( in perl) i have a file called "demo.exe" in my local unix host. i have a list of remote hosts in a file "hosts.txt" now i need to push "demo.exe" file to all the hosts in "hosts.txt" file. for this i need to prepare a script(in perl, but shell... (5 Replies)
Discussion started by: siva kumar
5 Replies

9. Shell Programming and Scripting

Not able to copy the file in perl cgi script

Hello experts, I am facing an very typical problem and hope the issue can be solved. I have a page download.cgi in /cgi-bin folder. use CGI; use CGI::Carp qw ( fatalsToBrowser ); use File::Copy copy("C:\\Program Files\\Apache Software... (8 Replies)
Discussion started by: scriptscript
8 Replies

10. Shell Programming and Scripting

Help in UNIX shell to copy part of file name to new file name

Hi, I want to do the following in a Unix shell script and wonder if someone could assist me? I want to take files in a specific directory that start with the name pxpur012 and copy them to the same directory with the file name not containg pxpur012. For example, I have files like... (4 Replies)
Discussion started by: lnemitz
4 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. "; 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}" string "CHARNAME" is first looked in the list of standard Unicode names of chars. 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}". 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: use charnames (); # for $charnames::hint_bits sub import { shift; $^H |= $charnames::hint_bits; $^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(@_); } } CUSTOM ALIASES
This version of charnames supports three mechanisms of adding local or customized aliases to standard Unicode naming conventions (:full) 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. 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. 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 does not exist, no warning is given and "undef" is returned. (Though if you ask for a code point past U+10FFFF you do get a warning.) BUGS
Since evaluation of the translation function happens in a 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.8.0 2002-06-01 charnames(3pm)
All times are GMT -4. The time now is 04:01 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy