remove non-alphabetic from a match line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting remove non-alphabetic from a match line
# 8  
Old 12-01-2011
Another way using "tr -cd" to list the characters you want to keep:
Code:
old_string="Products from [16]LG (295)"
new_string=`echo "${old_string}" | tr -cd '[A-Z][a-z][:space:]'`
echo "${new_string}"

Products from LG

# 9  
Old 12-01-2011
yeah, all of them working, but the thing is I don't want just one line of the product name az output, I want something like this:

input:

Code:
Some random data
Some random data
Some random data
Some random data
Some random data
Some random data
Some random data
Some random data
Some random data
Products from [16]LG (295)
Some random data
Some random data
Some random data
Some random data
Some random data
Products from [18]Sony Ericsson (135)
Some random data
Some random data
Some random data
Some random data
Some random data
Some random data
Some random data
Some random data
Some random data
Some random data

and the output like this:

Output

Code:
Some random data
Some random data
Some random data
Some random data
Some random data
Some random data
Some random data
Some random data
Some random data
Products fromLG
Some random data
Some random data
Some random data
Some random data
Some random data
Products fromSony Ericsson
Some random data
Some random data
Some random data
Some random data
Some random data
Some random data
Some random data
Some random data
Some random data
Some random data

So I want the whole file in the output, but the non_alphabetic charecters be removed from the lines that have the pattern "Product from".
# 10  
Old 12-01-2011
Code:
sed '/Products from/ s/[^ [:alpha:]//g' infile

(assuming you also want the spaces preserved, otherwise remove the space after ^)
This User Gave Thanks to CarloM For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Match pattern1 in file, match pattern2, substitute value1 in line

not getting anywhere with this an xml file contains multiple clients set up with same tags, different values. I need to parse the file for client foo, and change the value of tag "64bit" from false to true. cat clients.xml <Client type"FIX"> <ClientName>foo</ClientName>... (3 Replies)
Discussion started by: jack.bauer
3 Replies

2. Homework & Coursework Questions

Function to Check if string input from user is alphabetic only

Good Evening. I'm new to C. Can you please help me. I'm creating an error checking function, user will input a string, this will check if the input is all alphabet or all letters only. If there is a digit or other special char, it will print Error then ask input from user again. Here's my... (1 Reply)
Discussion started by: eracav
1 Replies

3. Shell Programming and Scripting

Awk-sed help : to remove first and last line with pattern match:

awk , sed Experts, I want to remove first and last line after pattern match "vg" : I am trying : # sed '1d;$d' works fine , but where the last line is not having vg entry it is deleting one line of data. - So it should check for the pattern vg if present , then it should delete the line ,... (5 Replies)
Discussion started by: rveri
5 Replies

4. Shell Programming and Scripting

I need to know how to replace a line after a pattern match with an empty line using SED

Hi How Are you? I am doing fine! I need to go now? I will see you tomorrow! Basically I need to replace the entire line containing "doing" with a blank line: I need to the following output: Hi How Are you? I need to go now? I will see you tomorrow! Thanks in advance.... (1 Reply)
Discussion started by: sags007_99
1 Replies

5. Shell Programming and Scripting

Remove line breaks after a match

I need to remove all line breaks in a document after a match, until there is a blank line. Example below, after the match "THE GREEN TABLE" remove line breaks until a blank line. Then, after the match "THE BLUE TABLE" do the same. Before: THE GREEN TABLE Lorem ipsum dolor sit amet,... (14 Replies)
Discussion started by: dockline
14 Replies

6. Shell Programming and Scripting

Delete line with match and previous line quoting/escaping problem

Hi folks, I've list of LDAP records in this format: cat cmmac.export.tmp2 dn: deviceId=0a92746a54tbmd34b05758900131136a506,ou=devices,ou=customer,ou=nl,o=upc cmmac: 00:13:11:36:a5:06 dn: deviceId=0a92746a62pbms4662299650015961cfa23,ou=devices,ou=customer,ou=nl,o=upc cmmac:... (4 Replies)
Discussion started by: tomas.polak
4 Replies

7. UNIX for Dummies Questions & Answers

sort file on timestamp and a alphabetic code in it

Hi, I have files like ER08EVENTDC080911232324.txt ER08EVENTCD080911232323.txt ER08EVENTCD080910222222.txt ER08EVENTCD080910130245.txt ER08EVENTAA080910130245.txt ER08EVENTAA080910232000.txt ER08EVENTAA080911015005.txt ER08EVENTAA080910130150.txt ER08EVENTAA080910232010.txt... (5 Replies)
Discussion started by: harshada
5 Replies

8. Shell Programming and Scripting

Quick regex question about alphabetic string

Hi guys, Pretty new to regex, and i know im doing something wrong here. I'm trying to get a regex command that restricts a string to be 8 characters long, and the first character cannot be 0. Here's what i have so far... echo "01234" | grep "^{8}*$" Thanks very much! -Crawf ... (7 Replies)
Discussion started by: crawf
7 Replies

9. UNIX for Dummies Questions & Answers

To convert the numeric month into alphabetic

hi , This function actually gives me the last month but as a numeric value what should i do to get it as suppose :Jul date '+%b %Y' | { read MONTH YEAR MONTH=`expr "$MONTH" - 1` echo $MONTH } Thanks. Rooh (2 Replies)
Discussion started by: rooh
2 Replies
Login or Register to Ask a Question