Sponsored Content
Top Forums Shell Programming and Scripting perl: reg.expr: combine starting and ending removal in one exprecion Post 302347757 by alex_5161 on Wednesday 26th of August 2009 10:35:21 AM
Old 08-26-2009
perl: reg.expr: combine starting and ending removal in one exprecion

Hello,
I am new in perl and in regular exprecion; so I am looking for help (or an experienced advise.)

The target is a triming spaces from a string: i.e., remove spases from begining and from end of a string.
One of main point of a searched solution is performance: for current task it is very important.
Therefore simple loop character by character seems to me ineffective.
I guess the reg.exp. engine should be pretty sufficient.
So, I've come out with:
Code:
 # $str = "   some text    "
  $str=~s/^[ ]*//;
  $str=~s/[ ]*$//;

This works fine,but,
first of all: I could not combine both patern into one exprecion.
Would you suggest how it could be done?
second: What about time? What expected to be longer : one more complicated regexp or twice, but simple? Who know how that task is processed inside of perl?

And last question: is there simpler way to do such simple task in perl?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Text replace by position instead of reg expr.

Can we replace the contents the of the rows of file, from one position to another position by mentioning, some start position & the width? (4 Replies)
Discussion started by: videsh77
4 Replies

2. Shell Programming and Scripting

var substitution in a reg expr ?

In a shell script, how I can achieve substitution of shell script var to a regular expression, as shown below. var=`head -1 file1` awk '$0!~/$var/ {print $0}' file1 > file2 In the case above $var value literally considered for non-exists criteria. (3 Replies)
Discussion started by: videsh77
3 Replies

3. UNIX for Dummies Questions & Answers

scipt dividing strings /reg expr

Hello! I've got txt-file containing lots of data in sentences like this: ;;BA;00:00:03:00;COM;CLOQUET-LAFOLLYE;SIMON; but sometime more than on in a line like this: ;;BA;00:00:03:00;COM;CLOQUET-LAFOLLYE;SIMON;;;BA;00:00:03:00;REA;RTL9;;;;BAC;:00;TIT;SEMAINE SPECIALE ~SSLOGAN~T DVD;; ... (3 Replies)
Discussion started by: maco_home
3 Replies

4. Shell Programming and Scripting

PERL: Simple reg expr validate 6 digits number

Hi there! I'm trying to validate a simple 6 digits number with reg expr. I ONLY want 6 digits so when i type 7 digits the script should no validate the number. I've write this code: #!/usr/bin/perl while(<STDIN>){ if($_=~/\d{6}/){ print "Bingo!\n"; ... (2 Replies)
Discussion started by: BufferExploder
2 Replies

5. Shell Programming and Scripting

print column that match reg expr

Hi all, I want to cut a column which match the regular expression "beta", if I don't know the column number? cat test alpha;beta;gamma 11;22;33 44;55;66 77;88;99 should be command .... beta 22 55 (6 Replies)
Discussion started by: research3
6 Replies

6. Programming

How to prevent incorrect string using reg expr in Java?

Hi All, I need your input on how to mask out / ignore a string that does not match a working regular expression (continually refining) pattern in Java. Below is the code snippet which is picking up all the lines with the correct regular expression string except one known so far: public... (0 Replies)
Discussion started by: gjackson123
0 Replies

7. Shell Programming and Scripting

if statement to check files with different ending but same starting name

I am trying to check if files staring with filename but ending with diffent dates e.g. filename.2011-10-25. The code I am using is below if It works find only if one file is present but returns binary operator expected when there are mulptiple files. Please help me correcting it. I... (5 Replies)
Discussion started by: ningy
5 Replies

8. UNIX for Advanced & Expert Users

Pring starting and ending numbers using UNIX

Hi all, I need to do scrip for printing starting and ending numbers along with count in given file.:wall: Input: a.txt 10000030 10000029 10000028 10000027 10000026 10000024 10000023 10000021 10000018 10000018 10000017 10000016 10000015 10000014 (2 Replies)
Discussion started by: jackbell2013
2 Replies

9. Shell Programming and Scripting

Text to column starting/ending with special character in each row

Hello, Here is my text data excerpted from the webpage: input My target is to get: What i tried is: sed 's/.*\(connector\)/1/' input > output but all characters coming before the word "connector" are deleted which is not good for me. My question: (9 Replies)
Discussion started by: baris35
9 Replies

10. UNIX for Beginners Questions & Answers

Search for words starting and ending with

im trying to search for a WORD in a file which begins with a number followed by a hypen follwed multiple words and end with a dot "." and pront the entire line which matches the above. Please note that there is a space at the begining of each line i/p file 19458 00000-CONTROL-PARA.... (5 Replies)
Discussion started by: anijan
5 Replies
addstr(3cur)															      addstr(3cur)

Name
       addstr, waddstr, mvaddstr, mvwaddstr - add string to window

Syntax
       #include <cursesX.h>

       int addstr(str)
       char *str;

       int waddstr(win, str)
       WINDOW *win;
       char *str;

       int mvaddstr(y, x, str)
       int y, x;
       char *str;

       int mvwaddstr(win, y, x, str)
       WINDOW *win;
       int y, x;
       char *str;

Description
       The routine writes all the characters of the null-terminated character string on the default window at the current (y, x) coordinates.

       The routine writes all the characters of the null terminated character string on the specified window at the current (y, x) coordinates.

       The routine writes all the characters of the null terminated character string on the default window at the specified (y, x) coordinates.

       The routine writes all the characters of the null terminated character string on the specified window at the specified (y, x) coordinates.

       The  following  information  applies to all the routines.  All the routines return if writing the string causes illegal scrolling.  In this
       case the routine will write as much as possible of the string on the window.

       These routines are functionally equivalent to calling or once for each character in the string.

       The routines and are macros.

Return Values
       The and functions return OK on success and ERR on error.

See Also
       addch(3cur), waddch(3cur)

																      addstr(3cur)
All times are GMT -4. The time now is 10:36 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy