Sponsored Content
Full Discussion: substr in perl
Top Forums UNIX for Dummies Questions & Answers substr in perl Post 302272734 by jim mcnamara on Wednesday 31st of December 2008 03:20:25 PM
Old 12-31-2008
See your other post. substr will work but it'll only work for you with a pipe delimited files that has all the exact same field and record lengths
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using substr

What is the more efficient way to do this (awk only and default FS) ? $ echo "jefe@alm"|awk '{pos = index($0, "@");printf ("USER: %s\n",substr ($0,1,pos-1))}' USER: jefe Thx in advance (2 Replies)
Discussion started by: Klashxx
2 Replies

2. UNIX for Dummies Questions & Answers

Substr

Hi, My input file is 41;2;xxxx;yyyyy.... 41;2;xxxx;yyyyy.... 41;2;xxxx;yyyyy.... .. .. I need to change the second field value from 2 to 1. i.e., 41;1;xxxx;yyyyy.... 41;1;xxxx;yyyyy.... 41;1;xxxx;yyyyy.... .. .. Thanks in advance. (9 Replies)
Discussion started by: deepakwins
9 Replies

3. Shell Programming and Scripting

get substr?

Hi, I have a long string like, aabab|bcbcbcbbc|defgh|paswd123 dedededede|efef|ghijklmn|paswd234 ghghghghgh|ijijii|klllkkk|paswd345 lmlmlmmm|nononononn|opopopopp|paswd456 This string is devided into one space between substrings. This substrings are, aabab|bcbcbcbbc|defgh|paswd123... (6 Replies)
Discussion started by: syamkp
6 Replies

4. Shell Programming and Scripting

copy substr in existing string in Perl

Any clue to write something to a particular location in Perl? Suppose $line = ‘abc cde 1234” How to write ( example string "test") on location 4 without parsing the whole line. Output should be $line = ‘abctest 1234” this is not search and replace. just to add substring into... (3 Replies)
Discussion started by: jaivipin
3 Replies

5. UNIX for Dummies Questions & Answers

substr function in perl

Hi friends, I have written a perl code and it works fine but I am not sure tommorow it works or not, please help me. problem : When diff is 1 then success other than its failure but tomorrow its 20090401 and the enddate is 20090331. thats why I write the code this type but it does not work and... (1 Reply)
Discussion started by: tukuna82
1 Replies

6. Shell Programming and Scripting

20090620231013 to date format i am using substr, any simple way in perl?

Hi Everyone, $tmp="20090620231013"; $tmp = substr($tmp,0,8)." ".substr($tmp,8,2).":".substr($tmp,10,2).":".substr($tmp,12,2); So my output is: 20090620 23:10:13. I only can think substr is easy, any perl can do this just one line very simple efficient one? :eek: Thanks (3 Replies)
Discussion started by: jimmy_y
3 Replies

7. Shell Programming and Scripting

perl file, one line code include "length, rindex, substr", slow

Hi Everyone, # cat a.txt a;b;c;64O a;b;c;d;ee;f # cat a.pl #!/usr/bin/perl use strict; use warnings; my $tmp3 = ",,a,,b,,c,,d,,e,,f,,"; open(my $FA, "a.txt") or die "$!"; while(<$FA>) { chomp; my @tmp=split(/\;/, $_); if ( ($tmp =~ m/^(64O)/i) || ($tmp... (3 Replies)
Discussion started by: jimmy_y
3 Replies

8. Shell Programming and Scripting

How to use if/else if with substr?

I have a command like this: listdb ID923 -l |gawk '{if (substr($0,37,1)==1 && NR == 3)print "YES" else if (substr ($0,37,1)==0 && NR == 3) print "NO"}' This syntax doesn't work. But I was able to get this to work: listdb ID923 -l |gawk '{if (substr($0,37,1)==1 && NR == 3)print "YES"}' ... (4 Replies)
Discussion started by: newbie2010
4 Replies

9. UNIX for Dummies Questions & Answers

Substr

awk '/^>/{id=$0;next}length>=7 { print id, "\n"$0}' Test.txt Can I use substr to achieve the same task? Thanks! (8 Replies)
Discussion started by: Xterra
8 Replies

10. Shell Programming and Scripting

Perl substr or similar help

I have a large string containing about 17,500 characters and I would like to obtain the value for token. token only appears in the entire string once and is towards the end of the string at the 17,200 area but that could change. Using perl can someone assist me with obtaining the value which in... (10 Replies)
Discussion started by: azdps
10 Replies
Prophet::Replica::prophet(3pm)				User Contributed Perl Documentation			    Prophet::Replica::prophet(3pm)

Replica Format
       overview

	$URL
	   /<db-uuid>/
	       /replica-uuid
	       /latest-sequence-no
	       /replica-version
	       /cas/records/<substr(sha1,0,1)>/substr(sha1,1,1)/<sha1>
	       /cas/changesets/<substr(sha1,0,1)>/substr(sha1,1,1)/<sha1>
	       /records (optional?)
		   /<record type> (for resolution is actually _prophet-resolution-<cas-key>)
		       /<record uuid> which is a file containing a list of 0 or more rows
			   last-changed-sequence-no : cas key

	       /changesets.idx

		   index which has records:
		       each record is : local-replica-seq-no : original-uuid : original-seq-no : cas key
		   ...

	       /resolutions/
		   /replica-uuid
		   /latest-sequence-no
		   /cas/<substr(sha1,0,1)>/substr(sha1,1,1)/<sha1>
		   /content (optional?)
		       /_prophet-resolution-<cas-key>	(cas-key == a hash the conflicting change)
			   /<record uuid>  (record uuid == the originating replica)
			       last-changed-sequence-no : <cas key to the content of the resolution>

		   /changesets.idx
		       index which has records:
			   each record is : local-replica-seq-no : original-uuid : original-seq-no : cas key
		       ...

       Inside the top level directory for the mirror, you'll find a directory named as a hex-encoded UUID.  This directory is the root of the
       published replica. The uuid uniquely identifes the database being replicated.  All replicas of this database will share the same UUID.

       Inside the <db-uuid> directory, are a set of files and directories that make up the actual content of the database replica:

       "replica-uuid"
	 Contains the replica's hex-encoded UUID.

       "replica-version"
	 Contains a single integer that defines the replica format.

	 The current replica version is 1.

       "latest-sequence-no"
	 Contains a single integer, the replica's most recent sequence number.

       "cas/records"
       "cas/changesets"
	 The "cas" directory holds changesets and records, each keyed by a hex-encoded hash of the item's content. Inside the "cas" directory,
	 you'll find a two-level deep directory tree of single-character hex digits.  You'll find  the changeset with the sha1 digest
	 "f4b7489b21f8d107ad8df78750a410c028abbf6c" inside "cas/changesets/f/4/f4b7489b21f8d107ad8df78750a410c028abbf6c".

	 You'll find the record with the sha1 digest "dd6fb674de879a1a4762d690141cdfee138daf65" inside
	 "cas/records/d/d/dd6fb674de879a1a4762d690141cdfee138daf65".

	 TODO: define the format for changesets and records

       "records"
	 Files inside the "records" directory are index files which list off all published versions of a record and the key necessary to retrieve
	 the record from the content-addressed store.

	 Inside the "records" directory, you'll     warn "Got types ".join(',',@types);find directories named for each "type" in your database.
	 Inside each "type" directory, you'll find a two-level directory tree of single hexadecimal digits. You'll find the record with the type
	 <Foo> and the UUID "29A3CA16-03C5-11DD-9AE0-E25CFCEE7EC4" stored in

	  records/Foo/2/9/29A3CA16-03C5-11DD-9AE0-E25CFCEE7EC4

	 The format of record files is:

	     <unsigned-long-int: last-changed-sequence-no><40 chars of hex: cas key>

	 The file is sorted in asecnding order by revision id.

       "changesets.idx"
	 The "changesets.idx" file lists each changeset in this replica and provides an index into the content-addressed storage to fetch the
	 content of the changeset.

	 The format of record files is:

	     <unsigned-long-int: sequence-no><16 bytes: changeset original source uuid><unsigned-long-int: changeset original source sequence no><16 bytes: cas key - sha1 sum of the changeset's content>

	 The file is sorted in ascending order by revision id.

       "resolutions"
	 TODO DOC RESOLUTIONS

   BUILD
       Open a connection to the prophet replica source identified by "$self-"url>.

   replica_version
       Returns this replica's version.

   set_replica_version
       Sets the replica's version to the given integer.

   uuid
       Return the replica's UUID

Internals of record handling
   changesets_for_record { uuid => $uuid, type => $type, limit => $int }
       Returns an ordered set of changeset objects for all changesets containing changes to this object.

       Note that changesets may include changes to other records

       If "limit" is specified, only returns that many changesets (starting from record creation).

perl v5.10.1							    2009-12-22					    Prophet::Replica::prophet(3pm)
All times are GMT -4. The time now is 07:50 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy