sed output with numbers


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed output with numbers
# 1  
Old 03-19-2010
Question sed output with numbers

I get the same value "chinchwad" for the following 3 statements.

Code:
echo "ABCDchinchwad18-Mar-2010-11.sql.zip" | sed -r 's/([A-Z]+)([a-z]+)(.*)/\2/'
echo "ABCDchinchwadII18-Mar-2010-11.sql.zip" | sed -r 's/([A-Z]+)([a-z]+)(.*)/\2/'
echo "ABCDchinchwad918-Mar-2010-11.sql.zip" | sed -r 's/([A-Z]+)([a-z]+)(.*)/\2/'

I expect:
chinchwad
chinchwadII
chinchwad9

The "ABCD" and the text after date "18-Mar" needs to be removed.

Last edited by pludi; 03-19-2010 at 10:28 AM.. Reason: code tags, please...
# 2  
Old 03-19-2010
Code:
echo ABCDchinchwad918-Mar-2010-11.sql.zip |
  LC_COLLATE=C sed -r 's/^[A-Z]*([^-]*)[0-9]{2,}-.*/\1/'

# 3  
Old 03-19-2010
If you get errors with the solution of radoulov (I do on a HP-UX) you can try:

Code:
sed 's/^[A-Z]*\([^-]*\)..-.*/\1/'

# 4  
Old 03-19-2010
Quote:
Originally Posted by Franklin52
If you get errors with the solution of radoulov (I do on a HP-UX)[...]
Yes, I used the non-standard r option and re-interval only because the OP seems to be using the GNU sed (or ssed?).
# 5  
Old 03-19-2010
Quote:
Originally Posted by radoulov
Yes, I used the non-standard r option and re-interval only because the OP seems to be using the GNU sed (or ssed?).
O yes, you're right, he seems to be using GNU sed.

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk - output-data always two numbers

Hi, my data is like the subsequent snipped. Fieldseperator is TAB. I can work the data well with awk, but the missing zero-numbers at the days column, for the days smaller 10 and the full hour-minutes i cant handle in the output. 2012 7 1 8 40 249.463 245.01 5.70448 6.11388 6.22125... (2 Replies)
Discussion started by: IMPe
2 Replies

2. Shell Programming and Scripting

sed with numbers

Patches have the following syntax: Patchxxxx.xxx where x is a number. I'm trying to strip the .xxx off of the patch, so I tried this: sed 's/PATCH./Patch/' patchin.log > patchout.log But that of course changed Patchxxxx.xxx to Patch. Ooops, what is the syntax i'm looking for? thanks (3 Replies)
Discussion started by: dba_frog
3 Replies

3. UNIX for Dummies Questions & Answers

Which command can help me output lines with duplicate numbers?

i have a file, let's call it file. march 2008 january 2008 march 1920 march 2002 i want to output the first line, not the second as you can see the second line has different numbers. (8 Replies)
Discussion started by: hobiwhenuknowme
8 Replies

4. Shell Programming and Scripting

add numbers to the output based on +/-

Add 35 to the 3rd col (12000) in input if it is "+" and it will be 12035 in output. Some thing like awk '{if ($3==+) print $2,$3,$3+35,$1 else print $2,$3-35,$3,$1}' + abc1 12000 - abc2 10000 + xyz1 11111 - vbcx 20036 + xy_z 33333 output abc1 ... (2 Replies)
Discussion started by: ruby_sgp
2 Replies

5. Shell Programming and Scripting

Perl output with negative and positive numbers

Hello, For my weather station I have made a little perl script to put the data into cacti. The next problem I have. I can only get positive numbers or negative numbers. What do I do: Though a shell scrip I call the perl script. Shell script: #!/bin/sh cat data.txt | stats.pl Perl... (4 Replies)
Discussion started by: rbl-blacklight
4 Replies

6. Shell Programming and Scripting

read numbers from file and output which numbers belongs to which range

Howdy experts, We have some ranges of number which belongs to particual group as below. GroupNo StartRange EndRange Group0125 935300 935399 Group2006 935400 935476 937430 937459 Group0324 935477 935549 ... (6 Replies)
Discussion started by: thepurple
6 Replies

7. Shell Programming and Scripting

ksh/awk help - output missing numbers

Here is what I am trying to do: I have a list of numbers that I pulled from an awk command in a column like so: 1 3 4 7 8 I want to find which numbers in the list are missing out of a range. So let's say I want to find out from the list above which numbers are missing from the... (6 Replies)
Discussion started by: afavis
6 Replies

8. Shell Programming and Scripting

Sub. numbers in column of output with If

This is my script. I am pulling the status of some hard where, but the status is in numerical form. The number 4 means Major and the 5 means Critical. In my script I would like to show the alarm type in aplha rather than numeric form. So if instead of seeing a 4 or 5 you would see MAjor or... (11 Replies)
Discussion started by: ja156194
11 Replies

9. Shell Programming and Scripting

output only numbers from mixed string

it must be late because I'm sure this is an easy task with grep sed or awk string would be anything mixing numbers letters and ) ( = output I need is just the numbers... but I just can't seem to get it to work. Any tips would be great :) (10 Replies)
Discussion started by: nortypig
10 Replies

10. Shell Programming and Scripting

formatting output in human readable numbers

Hi, The following command provides the usage in 1024-byte blocks du -ks * | sort -n | echo "$1" ... 1588820 user10 2463140 user11 2464096 user12 5808484 user13 6387400 user14 ..... I am trying to produce an output of first coulmn by multiplying by 1024 so that the output should... (11 Replies)
Discussion started by: ghazi
11 Replies
Login or Register to Ask a Question