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
# 1  
Old 12-01-2011
remove non-alphabetic from a match line

Hey all,

I want to remove non-alphabetic charecters from the line that have

"Products from "

for example a line like this:

Code:
Products from [16]LG (295)

should just become like

Code:
Products fromLG

in the file, and then I would delete the remaining and it would be just "LG"

tnx
# 2  
Old 12-01-2011
Code:
$> echo 'Products from [16]LG (295)'| sed 's/[^a-zA-Z ]//g'
Products from LG
$> echo 'Products from LG'| awk '{print $NF}'
LG
# or directly
$> echo 'Products from [16]LG (295)'| sed 's/.*]\([^ ]*\) .*/\1/'
LG

But not sure if you got more lines where there is a different constellation of characters etc.
# 3  
Old 12-01-2011
one more ..
Code:
$ a="Products from [16]LG (295)"
$ echo $a | tr -d "([])" | sed 's,[0-9],,g'
Products from LG

# 4  
Old 12-01-2011
it's a big file and one line should be converted like that, just the line that has "Products from"
# 5  
Old 12-01-2011
If I understand you correctly, the following should work
Code:
[skrynesaver@busybox ~]$ cat file
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: [12]LG(21)
Some random data
Some random data
Some random data
Some random data
Some random data
Products from: [12]Motorola(21)
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
[skrynesaver@busybox ~]$ egrep '^Products from' file|sed s'/Products from\(.\+\)/\1/g'|sed 's/[^[:alpha:]]//g'
LG
Motorola
[skrynesaver@busybox ~]$

# 6  
Old 12-01-2011
Quote:
Originally Posted by Johanni
it's a big file and one line should be converted like that, just the line that has "Products from"
Please enlighten us - did any of the provided solutions work for you or not? If not, what is going wrong? Thanks.
# 7  
Old 12-01-2011
Code:
sed -n '/Products/ s/Pr.*]\(.*\)(.*/\1/p' inputfile

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