matching a string followed by a number


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting matching a string followed by a number
# 1  
Old 01-03-2012
matching a string followed by a number

I have a string

Code:
joe-dimech-varp123.23-drw.msf
peter-erch-varp2.23-drw.msf
pawlu-donje-seru-varp3123.23-drw.msf

I want to remove the entry containing the varp tag (The varp is followed by a number)

I want to get
Code:
joe-dimech-drw.msf
peter-erch--drw.msf
 pawlu-donje-seru-drw.msf

# 2  
Old 01-03-2012
Hi kristinu,

One way using 'sed':
Code:
$ sed 's/varp[0-9][^-]*-//' infile
joe-dimech-drw.msf
peter-erch-drw.msf
pawlu-donje-seru-drw.msf

Regards,
Birei
# 3  
Old 01-03-2012
Using cut:
Code:
$ cut -d- -f1,2,4 inputfile
joe-dimech-drw.msf
peter-erch-drw.msf
pawlu-donje-varp3123.23

# 4  
Old 01-04-2012
Code:
$
$ cat f28
joe-dimech-varp123.23-drw.msf
peter-erch-varp2.23-drw.msf
pawlu-donje-seru-varp3123.23-drw.msf
$
$
$ perl -plne 's/-varp[\d.]+//' f28
joe-dimech-drw.msf
peter-erch-drw.msf
pawlu-donje-seru-drw.msf
$
$

tyler_durden
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Concatenate a string and number and compare that with another string in awk script

I have below code inside my awk script if ( $0 ~ /SVC IN:/ ) { svc_in=substr( $0,23 , 3); if (msg_start == 1 && msg_end == 0) { msg_arr=$0; } } else if ( $0 ~ /^SVC OUT:/ ) { svc_out=substr( $0, 9, 3); if (msg_start == 1 && msg_end == 0) ... (6 Replies)
Discussion started by: bhagya123
6 Replies

2. Shell Programming and Scripting

Remove matching pattern on each line with number variations

Hello folks! I have a file containing lines like this Something text 18:37Remove This: 1,111"Keep this text" Some more text 19:37Remove This: 222"Keep this text" More text 20:50Remove This: 3,333Keep this text And more text 25:50Remove This: 44,444Keep this text I would like to... (4 Replies)
Discussion started by: martinsmith
4 Replies

3. Shell Programming and Scripting

Matching a decimal number?

Hi everyone! Easy question for everyone. I'm trying to run a command line to find an exact match of a decimal number within a file. The number can be a positive OR negative number. For instance, if I want to find only the number -1 in the file that has: -17.6 -17 -16.3 -16.2 -15.7 -15.3... (6 Replies)
Discussion started by: lucshi09
6 Replies

4. Shell Programming and Scripting

Creating number by pattern matching

I have a certain mnemonic string from which I want to calculate a number The pattern follows three letters s, v and d. If a letter is by its own, the number assigned to the letter is assumed to be one. Else it takes the value preceeding it. I then need to add the numbers together. Example ... (5 Replies)
Discussion started by: kristinu
5 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

changing number in bash (number is in form of string)

I have a txt file as database. when i run my program what it does is it ask me for 3 name and stored in the file as name1:name2:name3:1 when u enter 3 name it add those in file as above format and add 1 at the end. I what i want is if i enter same names again it changes that 1 to 2 and so... (3 Replies)
Discussion started by: Learnerabc
3 Replies

7. Shell Programming and Scripting

find out line number of matching string using grep

Hi all, I want to display line number for matching string in a file. can anyone please help me. I used grep -n "ABC" file so it displays 6 ABC. But i only want to have line number,i don't want that it should prefix matching context with line number. Actually my original... (10 Replies)
Discussion started by: sarbjit
10 Replies

8. Shell Programming and Scripting

Finding the line number of matching braces

Hi,I am new to shell scripting and i want to find the line numbers of matching braces. The file contents are as follows File XXX.dat 1 ( CLASS "FRUIT" 2 (TYPE "PERSISTENT") 3 (MESSAGE_TYPE "M") 4 (GET_REQRD "Y") 5 (SET_REQRD "Y") 6 ) 7 ( CLASS... (3 Replies)
Discussion started by: Rajendra_1510
3 Replies

9. Shell Programming and Scripting

Need help matching a number

Using PERL. I have a variable called number. I need to match a range. The number can be no bigger than 6777 and no smaller than 2000. The number will always begin with a 2, 4, or 6. The next three numbers will range between 1 and 7. $number = xxxx I'm trying something like this but I... (1 Reply)
Discussion started by: x96riley3
1 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
Login or Register to Ask a Question