Help with grep, or alternative


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with grep, or alternative
# 1  
Old 05-09-2016
Help with grep, or alternative

say I have a big list of something like:

Code:
sdg2000
weghre10
fewg53
gwg99
jwegwejjwej43
afg10293

I want to remove the numbers of any line that has letters + 1 to 4 numbers

output:


Code:
sdg
weghre
fewg
gwg
jwegwejjwej
afg10293

# 2  
Old 05-09-2016
Any attempts/ideas/thoughts from your side?
# 3  
Old 05-09-2016
I have not tried, I don't know if grep can do that or not.. I know I can code it in VB6 but I also know the file size will not be supported.

The file size is 6.42 GB
# 4  
Old 05-09-2016
Well, would this come close:
Code:
sed '/[[:digit:]]\{5,\}/ !{/[[:alpha:]]/s/[[:digit:]]\+//}' file
sdg
weghre
fewg
gwg
jwegwejjwej
afg10293

# 5  
Old 05-09-2016
Quote:
Originally Posted by RudiC
Well, would this come close:
Code:
sed '/[[:digit:]]\{5,\}/ !{/[[:alpha:]]/s/[[:digit:]]\+//}' file
sdg
weghre
fewg
gwg
jwegwejjwej
afg10293

That worked great! Thank you.
# 6  
Old 05-09-2016
A few Perl alternatives.

Any of:
Code:
perl -pe 's/([a-zA-Z])\d{1,4}$/$1/' siwon.file
perl -pe 's/(?<=[a-zA-Z])\d{1,4}$//' siwon.file
perl -pe 's/([a-zA-Z])\d{1,4}(?!\d)/$1/' siwon.file

Code:
sdg
weghre
fewg
gwg
jwegwejjwej
afg10293

# 7  
Old 05-10-2016
Are the numbers always after the letters? In this case
Code:
egrep -v '[a-zA-Z][0-9]{1,4}'

should do it. Note that this assumes just plain ASCII letters. If you are worrying about other letters (accented characters, japanese text and so on), you can use character class expressions, and to what extend you have them available, depends on your grep version. Look at the grep manpage for details.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Alternative command to grep -w option

Hi All, We have few scripts where we are using grep -w option to do exact matching of the pattern. This works fine on most of our servers. But I have encounter a very old HP-UX System(HP-UX B.11.00) where grep -w option is not available. This is causing my scripts to fail. I need to change... (7 Replies)
Discussion started by: veeresh_15
7 Replies

2. Shell Programming and Scripting

Alternative for goto

#!/bin/sh label: echo sql poll v=`sqlplus -s <<! HR/HR set pages 0 echo off feed off select distinct status from emp where id=5; ! ` echo $v; echo it comes here after false if then echo if condition true sqlplus -l scott/tiger <<EOF select * from department; EXIT (2 Replies)
Discussion started by: kumaar1986
2 Replies

3. Shell Programming and Scripting

Please suggest alternative to grep

Hi Experts, PFB my requirement: I have a file (named file1) containing numbers like: 372846078543002 372846078543003 372846078543004 372846078543005 372846078543006 I have another file (nemed file2)where lines containing these numbers(present in file1) are present; Eg: lppza087; <PERFB >... (6 Replies)
Discussion started by: niladri29
6 Replies

4. UNIX for Dummies Questions & Answers

alternative to the grep trick

Hi, We used to use the below commands often. ps -ef|grep bc ps -ef|grep abc|grep -v grep Both fairly returns the same result. For example, the process name is dynamic and we are having the process name in a variable, how we can apply the above trick. For example "a" is the... (11 Replies)
Discussion started by: pandeesh
11 Replies

5. Solaris

vi alternative

Is there any other editor, installed by 'default' in Sparc Solaris10, besides vi? I'd like to avoid installing anything new. If not, how to make vi more user-friendly? thanks. (8 Replies)
Discussion started by: orange47
8 Replies

6. Shell Programming and Scripting

Alternative for wc -l

Hi techies .. This is my first posting hr .. Am facing a serious performance problem in counting the number of lines in the file. The input files i get will be in some 10 to 15 Gb of size or even sometimes more ..and I will load it to db I have used wc -l to confirm whether the loader... (14 Replies)
Discussion started by: rajesh_2383
14 Replies

7. Shell Programming and Scripting

Need best grep option or alternative

Hello, I am processing a text file which contains only words with few combination of characters (it is a dictionary file). example: havana have haven haven't havilland havoc Is there a way to exclude only 1 to 8 character long words which not include space or special characters : '-`~.. so... (5 Replies)
Discussion started by: alekkz
5 Replies

8. Shell Programming and Scripting

Alternative to grep

How to find a particular line in a file without using grep? (3 Replies)
Discussion started by: proactiveaditya
3 Replies

9. UNIX for Dummies Questions & Answers

Grep alternative to handle large numbers of files

I am looking for a file with 'MCR0000000716214' in it. I tried the following command: grep MCR0000000716214 * The problem is that the folder I am searching in has over 87000 files and I am getting the following: bash: /bin/grep: Arg list too long Is there any command I can use that can... (6 Replies)
Discussion started by: runnerpaul
6 Replies
Login or Register to Ask a Question