Perl Script Syntax to Extract Everything After Special Character


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl Script Syntax to Extract Everything After Special Character
# 1  
Old 09-01-2008
Perl Script Syntax to Extract Everything After Special Character

Hi,

I am writing a Perl script that reads in many lines, if a line meets the criteria I want to edit, it. For example, the script will return the following example line... test=abc123

All I want to do is strip off the "test=" and just be left with the abc123. In my script I can easily return everything before the "=" but for the life of me I can't get everything after the "=". A snipit of the code is...

$line3=<FILE>;
$line3=~ s/^\s+//; #strips off space
$line3=~s/=.*//; #returns everthing before "="

Any help would be greatly appreciated, thanks.

print "$line3\n";
# 2  
Old 09-01-2008
Just swap around the '=' and the '.*' in your last statement. You are currently doing a search-and-replace of '=' followed by any number of other characters with nothing, so you just want to reverse the two.
# 3  
Old 09-02-2008
Thanks Annihilannic, this worked perfectly.
# 4  
Old 10-05-2008
Bug Perl Script to Extract the Name of the Video out of a Youtube URL

First of all thanks for your help. I made this script out of the need to extract the youtube video name from a youtube address. I hope it helps.

Warmest regards,

Tony Mty

#!/usr/bin/perl
# s.u.f.y.a.
# Strip the Url From a Youtube Address
# Purpose: This small perl snippet will extract the name of the video out
# from a youtube address.
# Based on:
# https://www.unix.com/newreply.php?do=...=1&p=302231091
# hth
# tony mty
#
print "\Script to strip the url from a youtube address";
print "\nYoutube URL: ";
$youtubesurl = <STDIN>;
$youtubesurl=~ s/^\s+//; #strips off space
$youtubesurl=~s/.*watch\?v=//; #returns everthing after "watch?="
$youtubesurl=~s/&.*//; #returns everthing before "$"
print "$youtubesurl\n";
print "Done.\n";
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script question in special character

when I execute the unix commands its works normally in the 1st part. When I the tried the same in shell scripting the directory is not displayed in 2nd part example. please let me know what needs to be done. Unix : client=~zsvdbs echo $client /shome/zsvhome/zsvdbs Using... (3 Replies)
Discussion started by: keerthi2016
3 Replies

2. Shell Programming and Scripting

Trigger email from script if the Special Character replacement is successfull

Hello Gurus, I have a script developed... #!/bin/bash #--------------------------------------------------------------------- # This pScript will remove/replace the special characters fromfiles #--------------------------------------------------------------------- trxdate="`date... (1 Reply)
Discussion started by: nanduedi
1 Replies

3. 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

4. Shell Programming and Scripting

Use arrow touch in a script shell without special character

Hello, I have a problem when i execute the script underneath. If i tape azerty 123 and i use the arrow touch, in the file /tmp/test i have the caracter #!/usr/bin/ksh clear echo "Taper l adresse IP de la partition a creer :" tput cup 1 48 read Adress echo $Adress echo "${Adress}" >>... (0 Replies)
Discussion started by: khalidou13
0 Replies

5. Shell Programming and Scripting

Unix Perl split special character $

All I'm trying to split a string at the $ into arrays @data:=<dataFile> a $3.33 b $4.44 dfg $0.56 The split command I have been playing with is: split(/\$/, @data) which results with a .33 b .44 dfg .56 any help with this is appreciated /r Rick (9 Replies)
Discussion started by: schultz2146
9 Replies

6. UNIX for Advanced & Expert Users

Escaping special character stored in variables : perl

Hi just for regular use i m working on small module written in perl for getting date in specified format like i have to specify date format and then seperator to seperate date i am 95% done. now i m sure explanation i gave is not good enough so i am putting output here : C:\Documents and... (2 Replies)
Discussion started by: zedex
2 Replies

7. Shell Programming and Scripting

Perl Script Syntax error in version 4

Hi , I use the following simple perl script to find the yesterday time perl -e ' use POSIX(strftime); print POSIX::strftime("%a %b %e %H:%M:%S %Y", localtime(time-86400*$ARGV))' 1 However in the perl version 4 , it gives me the following error : Do the perl version 4 does not support... (4 Replies)
Discussion started by: youareapkman
4 Replies

8. UNIX for Dummies Questions & Answers

perl split funciton - special character "/"

HI, I have a directory structure. /abc/def/ghi/ I want to store it into array. So that if I do a pop function on that array I can easily go to previous directory. But how can i split and store it. @Directory = split(/\//,$DirectoryVarialbe) That doest works. Any other escape sequence... (5 Replies)
Discussion started by: deepakwins
5 Replies

9. Shell Programming and Scripting

Special Character Check in Shell script

Hi, I'm currently working on a project that requires parsing xml file. One of the field in the xml is shown below (don't remember exactly): <variable="ITEM">12345678</variable> I coded my script keeping in mind that the value denoted in bold will always be a number. After getting just the... (1 Reply)
Discussion started by: mradul_kaushik
1 Replies

10. Shell Programming and Scripting

Need help to extract a string delimited by any special character

I have a string as follows IS*blahblah TED~blahblah etc. I want to list down only IS and TED Can someone help me? (24 Replies)
Discussion started by: kumariak
24 Replies
Login or Register to Ask a Question