Visit Our UNIX and Linux User Community


matching alphanumeric string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting matching alphanumeric string
# 1  
Old 12-11-2001
Question matching alphanumeric string

how to match an alphanumeric string like the following.

i have to do like the following.

if the input line is

the data is {clock_91b}

i have to replace that with

the string was ("clock_91b")

i tried like

$line =~ s/the data is\s+\{([a-z]+)\}/the string was \(\"$1\"\)/

which is not working.
Is there any idea?
Smilie
sskb
# 2  
Old 12-11-2001
Well, sounds like homework to me, but looks like you have already put in the effort, and close to a solution, so I will reply (and chastise me if I shouldn't have, guys).

My solution does not use $1 (I need a little sed research myself), but instead uses \1 to back-reference the 1st parenthesized expression:

echo 'your input line' |
sed "s/the data is {\(.*\)}/the string was \(\"\1\"\)/"

and I did not have to escape the braces with backslashes.

Jimbo
Jimbo
# 3  
Old 12-11-2001
thanks jimbo, i could do that like this

$line =~ s/the data is {(.*)}/the string was \(\"$1\"\)/;

sorry for the confusion, since this is a model of the actual problem i faced. I could not give my company data directly here which would have been a solution for your doubt!

But sometimes it does not hear good to listen such comments when somebody tends to ask a question after a hectic session of trial in the office along with the tensions to finish the things within the last quarter of the year!!

well, thanks anyway.
Smilie
sskb
# 4  
Old 12-12-2001
My apologies, sskb. I am fairly new to this forum, and I will get better at spotting homework as opposed to someone trying to get their job done. I want to help (and learn in the process of helping), and follow the forum rules in the process.

I hope your year-end goes well, and Happy Holidays.
Jimbo
# 5  
Old 12-12-2001
thanks Jimbo for your understanding.
well, I am sorry if I have hurt you!!
wish you a happy christmas!
Smilie Smilie
sskb

Previous Thread | Next Thread
Test Your Knowledge in Computers #440
Difficulty: Medium
The term "GPU" was coined by Nvidia in 1994.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Generate a string of alphanumeric characters

Hi, I want a script of a code that will allow me to generate all possible combinations of alphanumberica characters of length 12 such that each string will contain numbers and either small or capital letters. For example a string may look like this: 123AB45cd678. (11 Replies)
Discussion started by: faizlo
11 Replies

2. UNIX for Beginners Questions & Answers

Need to compare numbers in alphanumeric string

Hi, I will be having file names like below, 1420SP1.01804 1420SP1.01805D 1420SP1.01805 1420SP1.01806D 1420SP1.01806 1420SP1.01901D 1420SP1.01901 1420SP1.01902D 1420SP1.01902 1420SP1.01903D 1420SP1.01903 1420SP1.01904 1420SP1.01905 From this, I need to list file names which is... (3 Replies)
Discussion started by: Sumanthsv
3 Replies

3. Shell Programming and Scripting

how to insert space in alphanumeric string

Hi everyone, I want help to insert space between digits and letters in a alphanumeric string. INPUT TRY234TER PHY1TYR EXPECTED OUTPUT TRY 234 TER PHY 1 TYR The lines always begin with the letters and the alphabets will be a three letter combination before and after the number. The... (2 Replies)
Discussion started by: kaav06
2 Replies

4. Shell Programming and Scripting

parse a mixed alphanumeric string from within a string

Hi, I would like to be able to parse out a substring matching a basic pattern, which is a character followed by 3 or 4 digits (for example S1234 out of a larger string). The main string would just be a filename, like Thisis__the FileName_S1234_ToParse.txt. The filename isn't fixed, but the... (2 Replies)
Discussion started by: keaneMB
2 Replies

5. Shell Programming and Scripting

Matching string from input to string of file

Hi, i want to know how to compare string of file with input string im trying following code: file_no=`paste -s -d "||||\n" a.txt | cut -c 1` #it will return collection number from file echo "enter number" read " curr_no" if ; then echo " current number already present" fi ... (4 Replies)
Discussion started by: a_smith
4 Replies

6. Shell Programming and Scripting

String matching

I have a string like ab or abc of whatever length. But i want to know whether another string ( for example, abcfghijkl, OR a<space> bcfghijkl ab<space> cfghijkl OR a<space>bcfghijkl OR ab<space> c<space> fghijkl ) starts with ab or abc... space might existing on the longer string... If so, i... (4 Replies)
Discussion started by: nram_krishna@ya
4 Replies

7. Shell Programming and Scripting

ksh - test if string contains alphanumeric...

Okay I will let users input spaces as well :) I am having a mental block. I have done a couple of searches but havent found anything that I understand (the likes of :alpha: and awk). Basically I want to give the user an option to enter some text which will go down as a field within a flat... (3 Replies)
Discussion started by: tugger
3 Replies

8. Shell Programming and Scripting

With Regex Spliting the string into Alphanumeric and Numeric part

Hi there With shell script I'm trying to split the string into two parts. One is alphanumeric part, the other one is a numeric part. dummy_postcode_1 = 'SL1' --> res_alpha = 'SL' and res_numeric = '1' dummy_postcode_2 = 'S053' --> res_alpha = 'S' and res_numeric = '053' ... (1 Reply)
Discussion started by: ozgurgul
1 Replies

9. UNIX for Dummies Questions & Answers

AlphaNumeric String Operations

Hi :) I am writing a ksh I have a string of general format A12B3456CD78 the string is of variable length the string always ends with numbers (here it is 78.. it can be any number of digits may be 789 or just 7) before these ending numbers are alphabets (here it is CD can even be... (3 Replies)
Discussion started by: lakshmikanth
3 Replies

10. Shell Programming and Scripting

sed problem - replacement string should be same length as matching string.

Hi guys, I hope you can help me with my problem. I have a text file that contains lines like this: 78 ANGELO -809.05 79 ANGELO2 -5,000.06 I need to find all occurences of amounts that are negative and replace them with x's 78 ANGELO xxxxxxx 79... (4 Replies)
Discussion started by: amangeles
4 Replies

Featured Tech Videos