sed for "/7.*" search and replace


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers sed for "/7.*" search and replace
# 1  
Old 01-13-2010
sed for "/7.*" search and replace

Hi ,
I have this file having thousands of records in it . I want to remove every 9 digit number starting with 7 in it . The few lines from the sample file are
Code:
"/-GEO-Prizm-Dashes-Covers-Caps-Trim/720000100-200742232-600022761.car"
"/StanPro-Jeep-CJ7/720000110-200742256-4199999702-10618.car"
"/-Pontiac-Solstice/720000110-200741374-10618.car"
"/-BMW-328IS-Exhaust-Emissions/720000410-200741808-600022949.car"
"/Flashlights/GP_2018185_N_111+20005392+600021964_10618.car"
"/Ball-Mounts/710040972-710070272-710040803-710066707-600022613.car"
"/Omix-Ada-Suzuki-Swift/720000100-200742369-4199999105-10618.car"

So I would like to have
Code:
"/-GEO-Prizm-Dashes-Covers-Caps-Trim/-200742232-600022761.car"
"/StanPro-Jeep-CJ7/-200742256-4199999702-10618.car"
"/-Pontiac-Solstice/-200741374-10618.car"
"/-BMW-328IS-Exhaust-Emissions/-200741808-600022949.car"
"/Flashlights/GP_2018185_N_111+20005392+600021964_10618.car"
"/Ball-Mounts/----600022613.car"
"/Omix-Ada-Suzuki-Swift/-200742369-4199999105-10618.car"

Thanks ,

Last edited by Scott; 01-13-2010 at 02:45 PM.. Reason: Please use code tags
# 2  
Old 01-13-2010
I think this will do the trick:
Code:
sed -r 's/7[0-9]{8}//g' file

# 3  
Old 01-13-2010
I tried the solution here but it is not changing anything in the file .

Before using sed

Code:
 cat XSITEMAP_CP_REQUEST_sample.DEL
"/-Mazda-Hitches/720000300-710040783-20005332-600022614.car"
"/SECURITY-CHAIN-CABLE-TIRE-CHAINS/GP_2003907_N_111+20005365+720000200_10618.car"
"/Hitch-Balls-Mounts/710040972-710070308-710070284-710070295-600022610.car"
"/Equus-Ford-Explorer/720000110-200742413-4199999045-10618.car"
"/VDP-WIND-STOPPER-/GP_2009879_N_111+200742256+600022787+4199998445_10618.car"
"/Nissan-Titan-Performance-Air-Filters/200742471-600023074.car"
"/-GEO-Prizm-Dashes-Covers-Caps-Trim/720000100-200742232-600022761.car"
"/StanPro-Jeep-CJ7/720000110-200742256-4199999702-10618.car"
"/-Pontiac-Solstice/720000110-200741374-10618.car"
"/-BMW-328IS-Exhaust-Emissions/720000410-200741808-600022949.car"
"/Flashlights/GP_2018185_N_111+20005392+600021964_10618.car"
"/Ball-Mounts/710040972-710070272-710040803-710066707-600022613.car"
"/Omix-Ada-Suzuki-Swift/720000100-200742369-4199999105-10618.car"


After using sed

Code:
 sed -e 's/7[0-9]{8}//g' XSITEMAP_CP_REQUEST_sample.DEL > XSITEMAP_CP_REQUEST_sample.DEL1

$ cat XSITEMAP_CP_REQUEST_sample.DEL1
"/-Mazda-Hitches/720000300-710040783-20005332-600022614.car"
"/SECURITY-CHAIN-CABLE-TIRE-CHAINS/GP_2003907_N_111+20005365+720000200_10618.car"
"/Hitch-Balls-Mounts/710040972-710070308-710070284-710070295-600022610.car"
"/Equus-Ford-Explorer/720000110-200742413-4199999045-10618.car"
"/VDP-WIND-STOPPER-/GP_2009879_N_111+200742256+600022787+4199998445_10618.car"
"/Nissan-Titan-Performance-Air-Filters/200742471-600023074.car"
"/-GEO-Prizm-Dashes-Covers-Caps-Trim/720000100-200742232-600022761.car"
"/StanPro-Jeep-CJ7/720000110-200742256-4199999702-10618.car"
"/-Pontiac-Solstice/720000110-200741374-10618.car"
"/-BMW-328IS-Exhaust-Emissions/720000410-200741808-600022949.car"
"/Flashlights/GP_2018185_N_111+20005392+600021964_10618.car"
"/Ball-Mounts/710040972-710070272-710040803-710066707-600022613.car"
"/Omix-Ada-Suzuki-Swift/720000100-200742369-4199999105-10618.car"


Thanks ,

Last edited by pludi; 01-13-2010 at 02:33 PM.. Reason: code tags, please...
# 4  
Old 01-13-2010
It looks like you used '-e', but I just tried it with '-r' and I saw the change.
# 5  
Old 01-13-2010
It throws an error with -r

Code:
sed -r 's/7[0-9]{8}//g' XSITEMAP_CP_REQUEST_sample.DEL
sed: illegal option -- r



---------- Post updated at 01:07 PM ---------- Previous update was at 01:06 PM ----------

Sorry , I didn't mention , it is SUNOS

Code:
uname -a
SunOS jcw-qadb 5.8 Generic_108528-29 sun4u sparc SUNW,Sun-Fire-V440


Last edited by pludi; 01-13-2010 at 02:34 PM.. Reason: code tags, please...
# 6  
Old 01-13-2010
It seems like with using '-e', you will need to write out [0-9] 8 times instead of using the shortcut '{8}'. Not sure why this is, but it worked for me.

Last edited by 2pugs; 01-13-2010 at 02:13 PM.. Reason: Formatting
# 7  
Old 01-13-2010
Yes, -r allows to use Extended Regular Expressions, maybe unavailable on SunOS.
What does
Code:
sed --help

tell?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using sed command to replace "|" with ^ for all *.dat files in a folder not working

I am trying to use the below sed command to replace all "|" to ^, in a folder had 50 dat files. when i tried with 1 file it worked but when i tried with wild card, is not working. sed -i 's/"|"/\^/g' *.dat Is this the proper way to use sed command thank you very much for help. (3 Replies)
Discussion started by: cplusplus1
3 Replies

2. Shell Programming and Scripting

grep with "[" and "]" and "dot" within the search string

Hello. Following recommendations for one of my threads, this is working perfectly : #!/bin/bash CNT=$( grep -c -e "some text 1" -e "some text 2" -e "some text 3" "/tmp/log_file.txt" ) Now I need a grep success for some thing like : #!/bin/bash CNT=$( grep -c -e "some text_1... (4 Replies)
Discussion started by: jcdole
4 Replies

3. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

4. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

5. Shell Programming and Scripting

Awk to Search and Replace inside the pipe "|"

Hi, Anyone can help me on how to replace the qoutes inside the pipe | in my Text File like belows; "AAAA"|"Test "1-A""|"Test AAAA"|"This is A" "BBBB"|"Test "1-B""|"Test BBBB"|"This is B" "CCCC"|"My Test C"|"Test "CCCC""|"This is C" The output I need like belows; "AAAA"|"Test 1-A"|"Test... (12 Replies)
Discussion started by: fspalero
12 Replies

6. Shell Programming and Scripting

Script to search a string which is in between "" and replace it with another character

Hi, I am trying to search a string from a text file which is in between "" (Double Quotes) (Eg: "Unix"), and replace it with a | where ever it is appearing in the text file and save the file. Please help me. -kkmdv (6 Replies)
Discussion started by: kkmdv
6 Replies

7. Shell Programming and Scripting

Interesting question - Search and replace the word after sign "="

Hi Guys, Req your help in searching and replacing the word that comes after equals(=) symbol I would like to replace the sting in bold with a string in variable. d=ABCDF8C44C22 # grep -i NIM_MASTERID ${_NIMINFO} export NIM_MASTERID=00CDF8C44C00 I'm looking to replace any word that... (4 Replies)
Discussion started by: ajilesh
4 Replies

8. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

9. Shell Programming and Scripting

Sed , Replace a "variable text" inside of a statement

Please Help... I am trying to manipulte the following line Before : <user:Account_Password>002786</user:Account_Password> the password is the "variable", i need to delete / omit the password in the file, (it occurs several thousand times) so the tag line looks like After:... (4 Replies)
Discussion started by: jackn7
4 Replies

10. UNIX for Dummies Questions & Answers

Search and Replace with "sed

I have a file containung a list. each object in the list has 3 parts, which i will refer as x y z I need to replace the x y z with the x alone and send it to a different file. The x size is one caracter but it's value is changing. the y contained the x charecter, so I cant use the simple "sed"... (1 Reply)
Discussion started by: sunbird
1 Replies
Login or Register to Ask a Question