Help needed in excluding certain word patterns


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help needed in excluding certain word patterns
# 1  
Old 11-04-2015
Help needed in excluding certain word patterns

Hi,

I need help with following. I need to exclude words that match following patterns
a. more than length 4 (example SBRAP)
b. contains mixture uppercase and lower case regardless of the length (example GSpD)

File contains
Code:
COFpC
MCHX
SP
SNFCA
GEH
SBRAP
DGICA
JPMpE
WFCpP
GSpD
AXL
RGS
PREpD
EVN
CNOB
CUBI
TOWN
GSpD
RGS
EVN
CNOB
CUBI

Thanks
jak
# 2  
Old 11-04-2015
Code:
perl -nle 'print unless (length > 4 or (/[A-Z]/ and /[a-z]/))' jakSun8.file
MCHX
SP
GEH
AXL
RGS
EVN
CNOB
CUBI
TOWN
RGS
EVN
CNOB
CUBI

# 3  
Old 11-05-2015
Thanks Aia but i don't have perl installed on my system. Any awk or sed solution please?

Thanks,
jak
# 4  
Old 11-05-2015
Any attempt from your side, please?

Code:
awk 'length <=4 && !(/[a-z]/ && /[A-Z]/)' file

or
Code:
awk 'length <=4 && !(tolower($0) == $0 || toupper($0) == $0)' file

# 5  
Old 11-05-2015
Thanks RudiC. I am not well versed in scripting language but appreciate folks like you who help out generously on daily basis.

Thanks,
jak
# 6  
Old 11-05-2015
Sed version:
--
Code:
sed '/.\{5\}/d; /[a-z][A-Z]/d; /[A-Z][a-z]/d' file

or (better)
Code:
sed '/.\{5\}/d; /[[:lower:]][[:upper:]]/d; /[[:upper:]][[:lower:]]/d' file

--
If we only want to print either only lower case or only uppercase (not allowing any other characters)

Code:
sed -n '/^[A-Z]\{1,4\}$/p; /^[a-z]\{1,4\}$/p' file

or (better)
Code:
sed -n '/^[[:upper:]]\{1,4\}$/p; /^[[:lower:]]\{1,4\}$/p' file

or grep:
Code:
grep -Ee '^[[:upper:]]{1,4}$' -e '^[[:lower:]]{1,4}$' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash - Find files excluding file patterns and subfolder patterns

Hello. For a given folder, I want to select any files find $PATH1 -f \( -name "*" but omit any files like pattern name ! -iname "*.jpg" ! -iname "*.xsession*" ..... \) and also omit any subfolder like pattern name -type d \( -name "/etc/gconf/gconf.*" -o -name "*cache*" -o -name "*Cache*" -o... (2 Replies)
Discussion started by: jcdole
2 Replies

2. Shell Programming and Scripting

Find matched patterns and print them with other patterns not the whole line

Hi, I am trying to extract some patterns from a line. The input file is space delimited and i could not use column to get value after "IN" or "OUT" patterns as there could be multiple white spaces before the next digits that i need to print in the output file . I need to print 3 patterns in a... (3 Replies)
Discussion started by: redse171
3 Replies

3. Shell Programming and Scripting

Help needed in excluding word

Hello, When i run this command find ./ -type f -print | xargs grep -l 'myWord' it prints the file name where 'myWord' exists and also something like the below which i want to exclude grep: can't open Fields grep: can't open Search I tried piping and grep -v 'open' but it did not work. ... (3 Replies)
Discussion started by: jakSun8
3 Replies

4. Shell Programming and Scripting

Excluding patterns from a list

I have the following code that takes the command line arguments. However I want to remove from the command line list the user options. For example, removing --quiet --shift=3 sort=4/5/6 I have written the following code to take care of this situation. set strLst = `echo $argv | tr '... (3 Replies)
Discussion started by: kristinu
3 Replies

5. Shell Programming and Scripting

extracting part of a line excluding particular word from it

here is the line on which i want to process `empNo` int(13) NOT NULL AUTO_INCREMENT, it sometimes doesnt have comma at the end too `empNo` int(13) NOT NULL AUTO_INCREMENT i want to extract all except "AUTO_INCREMENT" not only this line i ,want the code to work on any line if it has... (5 Replies)
Discussion started by: vivek d r
5 Replies

6. UNIX for Dummies Questions & Answers

How to get complete path in variable excluding last word?

Hello Experts, Can you please help me by providing a code which can give me the complete path except last word in a variable, the variable i can use anywhere else for my operation eg: if this below one is my path: ... (3 Replies)
Discussion started by: aks_1902
3 Replies

7. Shell Programming and Scripting

grep middle word between two patterns

Hi, I'm currently working on a shell script to automate a backup check on oracle database. My requirement is to grep the words between two delimiters and pass on to a variable.. for ex I have following values in my log file... (DB_NAME), (163.24 25), (16/02/10 23:40), (COMPLETED), I want... (5 Replies)
Discussion started by: senthil3d
5 Replies

8. Shell Programming and Scripting

Word count while excluding

Hello, Is there a way to word count a file while excluding lines that have FRP in them? wc -l "filename"? Thanks in advance Gideon (4 Replies)
Discussion started by: blitzkreg6
4 Replies

9. UNIX for Dummies Questions & Answers

printing only the middle word between two patterns

How would I print the word "and" between the words "FOO" and BAR" using sed? My file has three words in it FOO and BAR. I only want the word "and". Thanks every one. (7 Replies)
Discussion started by: tigta09
7 Replies

10. Shell Programming and Scripting

grep multiple patterns + the whole word only

Guys, i used egrep "pattern1|pattern2". But the whole word is searched. But i want the output if only the exact word is matched. i.e the output is got evenif a part of the pattern is matched. I tried the -w opion but its showing usage error. Please help me out on this one. please sent me... (2 Replies)
Discussion started by: meheretoknow
2 Replies
Login or Register to Ask a Question

Featured Tech Videos