Sponsored Content
Full Discussion: split string using sed, perl
Top Forums Shell Programming and Scripting split string using sed, perl Post 302711753 by som.nitk on Monday 8th of October 2012 02:19:32 AM
Old 10-08-2012
Why does it not match any alphanumeric characters with following?

Code:
 
if ($var =~ /^((?:[a-zA-Z0-9]*\^~\^){2})(.*)/) {
 $string1 = $1;
 $string2 = $2;
}


Last edited by som.nitk; 10-08-2012 at 03:31 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

split string help

could anyone help in running split cmd split("String1,outputArray,"delimiter); with sample script?. for eg i have abc-def-ghi-sdf- my ultimate aim of asking this is i have a string containing hypens, i want to get the string before last n(2) Hypens (4 Replies)
Discussion started by: senthilk615
4 Replies

2. Shell Programming and Scripting

Split a file based on pattern in awk, grep, sed or perl

Hi All, Can someone please help me write a script for the following requirement in awk, grep, sed or perl. Buuuu xxx bbb Kmmmm rrr ssss uuuu Kwwww zzzz ccc Roooowwww eeee Bxxxx jjjj dddd Kuuuu eeeee nnnn Rpppp cccc vvvv cccc Rhhhhhhyyyy tttt Lhhhh rrrrrssssss Bffff mmmm iiiii Ktttt... (5 Replies)
Discussion started by: kumarn
5 Replies

3. Shell Programming and Scripting

Split A String

Hi, I am new to scripting and need help splitting a string using space as the delimiter. How can I do that? I want the result to be stored in an Array. I tried using set -A arr $(echo $FILE) echo $arr The result of the above was ''. Thanks. (2 Replies)
Discussion started by: newbie187
2 Replies

4. UNIX for Dummies Questions & Answers

Trim String in 3rd Column in Tab Delimited File...SED/PERL/AWK?

Hey Everybody, I am having much trouble figuring this out, as I am not really a programmer..:mad: Datafile.txt Column0 Column1 Column2 ABC DEF xxxGHI I am running using WGET on a cronjob to grab a datafile, but I need to cut the first three characters from... (6 Replies)
Discussion started by: rickdini
6 Replies

5. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

6. Shell Programming and Scripting

Oneliner ---split string to character by piping shell output to perl

Hello, I was trying to split a string to characters by perl oneliner. echo "The quick brown fox jumps over the lazy dog" | perl -e 'split // ' But did not work as with bash script pipe: echo "The quick brown fox jumps over the lazy dog" | fold -w1 | sort | uniq -ic 8 1 T 1... (6 Replies)
Discussion started by: yifangt
6 Replies

7. Shell Programming and Scripting

Split the string in perl

Hi All, How to split the string KAR_Celltick_Ban_GSMGW3 and want to pickup the third filed. Sometime the string may be "KAR_Celltick_Ban" like this Thanks in advance (1 Reply)
Discussion started by: sujit_kashyap
1 Replies

8. Shell Programming and Scripting

Perl split string separated by special character

Hello I have string (string can have more sections) LINE="AA;BB;CC;DD;EE"I would like to assigne each part of string separated by ";" to some new variable. Can someone help? (4 Replies)
Discussion started by: vikus
4 Replies

9. Shell Programming and Scripting

sed split string

Greetings, i have a string that looks like Network "123" "ABC" i need to make it look like: Network "123" Network "ABC" Help please? Thanks again Please use CODE tags when displaying sample input, sample output, and code segments (as required by forum rules). (2 Replies)
Discussion started by: hoyanet
2 Replies

10. UNIX for Beginners Questions & Answers

Using sed to split hex string

Hi, I'm looking to split the following hex string into rows of four elements. I've tried the following but it doesn't seem to work. How can I tell sed to match based on a pair of number(s) and letter(s), and add a newline every 4 pairs? In addition, I need to add another newline after every... (5 Replies)
Discussion started by: sand1234
5 Replies
TR(1)							    BSD General Commands Manual 						     TR(1)

NAME
tr -- translate characters SYNOPSIS
tr [-cs] string1 string2 tr [-c] -d string1 tr [-c] -s string1 tr [-c] -ds string1 string2 DESCRIPTION
The tr utility copies the standard input to the standard output with substitution or deletion of selected characters. The following options are available: -c Complements the set of characters in string1, that is -c ab includes every character except for 'a' and 'b'. -d The -d option causes characters to be deleted from the input. -s The -s option squeezes multiple occurrences of the characters listed in the last operand (either string1 or string2) in the input into a single instance of the character. This occurs after all deletion and translation is completed. In the first synopsis form, the characters in string1 are translated into the characters in string2 where the first character in string1 is translated into the first character in string2 and so on. If string1 is longer than string2, the last character found in string2 is dupli- cated until string1 is exhausted. In the second synopsis form, the characters in string1 are deleted from the input. In the third synopsis form, the characters in string1 are compressed as described for the -s option. In the fourth synopsis form, the characters in string1 are deleted from the input, and the characters in string2 are compressed as described for the -s option. The following conventions can be used in string1 and string2 to specify sets of characters: character Any character not described by one of the following conventions represents itself. octal A backslash followed by 1, 2 or 3 octal digits represents a character with that encoded value. To follow an octal sequence with a digit as a character, left zero-pad the octal sequence to the full 3 octal digits. character A backslash followed by certain special characters maps to special values. a <alert character>  <backspace> f <form-feed> <newline> <carriage return> <tab> v <vertical tab> A backslash followed by any other character maps to that character. c-c Represents the range of characters between the range endpoints, inclusively. [:class:] Represents all characters belonging to the defined character class. Class names are: alnum <alphanumeric characters> alpha <alphabetic characters> blank <blank characters> cntrl <control characters> digit <numeric characters> graph <graphic characters> lower <lower-case alphabetic characters> print <printable characters> punct <punctuation characters> space <space characters> upper <upper-case characters> xdigit <hexadecimal characters> With the exception of the ``upper'' and ``lower'' classes, characters in the classes are in unspecified order. In the ``upper'' and ``lower'' classes, characters are entered in ascending order. For specific information as to which ASCII characters are included in these classes, see ctype(3) and related manual pages. [=equiv=] Represents all characters or collating (sorting) elements belonging to the same equivalence class as equiv. If there is a sec- ondary ordering within the equivalence class, the characters are ordered in ascending sequence. Otherwise, they are ordered after their encoded values. An example of an equivalence class might be ``c'' and ``ch'' in Spanish; English has no equivalence classes. [#*n] Represents n repeated occurrences of the character represented by #. This expression is only valid when it occurs in string2. If n is omitted or is zero, it is interpreted as large enough to extend string2 sequence to the length of string1. If n has a lead- ing zero, it is interpreted as an octal value, otherwise, it's interpreted as a decimal value. EXIT STATUS
tr exits 0 on success, and >0 if an error occurs. EXAMPLES
The following examples are shown as given to the shell: Create a list of the words in file1, one per line, where a word is taken to be a maximal string of letters: tr -cs "[:alpha:]" " " < file1 Translate the contents of file1 to upper-case: tr "[:lower:]" "[:upper:]" < file1 Strip out non-printable characters from file1: tr -cd "[:print:]" < file1 COMPATIBILITY
AT&T System V UNIX has historically implemented character ranges using the syntax ``[c-c]'' instead of the ``c-c'' used by historic BSD implementations and standardized by POSIX. AT&T System V UNIX shell scripts should work under this implementation as long as the range is intended to map in another range, i.e. the command tr [a-z] [A-Z] will work as it will map the '[' character in string1 to the '[' character in string2. However, if the shell script is deleting or squeezing characters as in the command tr -d [a-z] the characters '[' and ']' will be included in the deletion or compression list which would not have happened under an historic AT&T System V UNIX implementation. Additionally, any scripts that depended on the sequence ``a-z'' to represent the three characters 'a', '-', and 'z' will have to be rewritten as ``a-z''. The tr utility has historically not permitted the manipulation of NUL bytes in its input and, additionally, stripped NUL's from its input stream. This implementation has removed this behavior as a bug. The tr utility has historically been extremely forgiving of syntax errors, for example, the -c and -s options were ignored unless two strings were specified. This implementation will not permit illegal syntax. STANDARDS
The tr utility is expected to be IEEE Std 1003.2 (``POSIX.2'') compatible. It should be noted that the feature wherein the last character of string2 is duplicated if string2 has less characters than string1 is permitted by POSIX but is not required. Shell scripts attempting to be portable to other POSIX systems should use the ``[#*]'' convention instead of relying on this behavior. BUGS
tr was originally designed to work with US-ASCII. Its use with character sets that do not share all the properties of US-ASCII, e.g., a sym- metric set of upper and lower case characters that can be algorithmically converted one to the other, may yield unpredictable results. tr should be internationalized. BSD
March 23, 2004 BSD
All times are GMT -4. The time now is 11:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy