delete all text before the /
Hi Guys
So I have a text file with over 25000 lines similar to this. BRI005/0116253000 sedi's/CorporateServicesadivisionofBridgeFax/0116253090 And I need to change it so it comes at as follows sed -i 's/0116253000/CorporateServicesadivisionoofBridge/g' /tmp/*.txt Is that possible with sed or anything? Thanks |
Quote:
It is almost certain that sed or grep will do the job. Daniel B. Martin |
What? I think I perhaps understand the question, but the examples you posted are confusing me. Except for the first line they look like they are already sed commands (at least sorta). Could you please explain more clearly?
And please use ***[code][/code]*** tags around your code and data, to preserve the original formatting and to improve readability. Do not use quote tags, bolding, colors, "start/end" lines, or other creative techniques. A basic sed command that would remove everything up to the first slash would look like this: Code:
sed -i 's_[^/]*/_/_' infile |
here is how it looks currently
BEV/010/0114441030 BEV/02/0114404855 BHE0/01/0114945/020 BIB0/01118/022955 BIG003/0118/020560 sedi's/BigenAfricaFax/0118/020565 BIL003/0116562/024 BIZ0/01/0114472757 ATTENTION/0117040/026NormalTerms2 BLA004/0116568044 BLI0/01112622299 BLU003/011/0218216 BLU009/0118353807 BMG0/01/0117935400 BOA121/0117927663 sedi's/BoardroomSolutions30dayfrmInvFax/0117936209 BOL0/01/0119827671 sedi's/BolelaVoiceanddataCablingFax/0119829700 BOL003/0118947748 BOR0/01/0118043252 BOT005/0117912529/30 sedi's/BotarProcurement&LogisticsccFax/0117928227 BSC0/02/0114634779 I need it to look like sed -i's/0114404855/BigenAfrica/g' /tmp/*.txt sed -i 's/0114472757/ATTENTION/g' /tmp/*.txt sed -i 's/0117927663/BoardroomSolutions/g' /tmp/*.txt sed -i 's/0117912529/BotarProcurement&Logisticscc/g' /tmp/*.txt |
Quote:
So firstly, please use [code][/code] tags around your code and data. Secondly, show the actual desired output required. |
How did you get from here...
Code:
BEV/010/0114441030 Code:
sed -i's/0114404855/BigenAfrica/g' /tmp/*.txt Daniel B. Martin |
Ok maybe let me explain a bit better.
So I have an excel spreadsheet with over 45000 lines and it has a lot of junk data. I need to filter out all the data except company name and no then I need that to be put into a sed command. I want to copy all the sed commands into a bash script that will convert a text file on a weekly basis an eg of the script is below friday=`date +%F` monday=`date +%F --date="+4 days ago"` SUBJECT="Weekly calls report" EMAIL="xxx@xxx.co.za" CC="xxx@xxx.co.za" ATTACHMENT="/tmp/*.txt" BODY="/home/body.txt" mysql xxxx -u root -pxxxx<<EOFMYSQL select calldate as 'DATE',src as 'DIALED-NO',dst as 'DESTINATION', (billsec /* = an int */ / 60) as 'DURATION(seconds)' from cdr where calldate > '$monday 00:00:00' and calldate < '$friday 23:59:00' and src ='30' and dst LIKE '0%' and disposition ='ANSWERED' INTO OUTFILE '/tmp/cedwin.txt'FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'LINES TERMINATED BY '\n'; EOFMYSQL sleep 5 mysql xxxx -u root -pxxxx<<EOFMYSQL select calldate as 'DATE',src as 'DIALED-NO',dst as 'DESTINATION', (billsec /* = an int */ / 60) as 'DURATION(seconds)' from cdr where calldate > '$monday 00:00:00' and calldate < '$friday 23:59:00' and src ='22' and dst LIKE '0%' and disposition ='ANSWERED' INTO OUTFILE '/tmp/megan.txt'FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'LINES TERMINATED BY '\n'; EOFMYSQL sleep 5 mysql xxxx -u root -pxxxx<<EOFMYSQL select calldate as 'DATE',src as 'DIALED-NO',dst as 'DESTINATION', (billsec /* = an int */ / 60) as 'DURATION(seconds)' from cdr where calldate > '$monday 00:00:00' and calldate < '$friday 23:59:00' and src ='14' and dst LIKE '0%' and disposition ='ANSWERED' INTO OUTFILE '/tmp/olwethu.txt'FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'LINES TERMINATED BY '\n'; EOFMYSQL sleep 5 mysql xxx -u root -pxxxx<<EOFMYSQL select calldate as 'DATE',src as 'DIALED-NO',dst as 'DESTINATION', (billsec /* = an int */ / 60) as 'DURATION(seconds)' from cdr where calldate > '$monday 00:00:00' and calldate < '$friday 23:59:00' and src ='23' and dst LIKE '0%' and disposition ='ANSWERED' INTO OUTFILE '/tmp/jean.txt'FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'LINES TERMINATED BY '\n'; EOFMYSQL sleep 5 mysql xxxxx -u root -pxxxxx<<EOFMYSQL select calldate as 'DATE',src as 'DIALED-NO',dst as 'DESTINATION', (billsec /* = an int */ / 60) as 'DURATION(seconds)' from cdr where calldate > '$monday 00:00:00' and calldate < '$friday 23:59:00' and src ='19' and dst LIKE '0%' and disposition ='ANSWERED' INTO OUTFILE '/tmp/hayley.txt'FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'LINES TERMINATED BY '\n'; EOFMYSQL sleep 5 sed -i 's/074318520/Dorcas/g' /tmp/*.txt sed -i 's/0712472533/Hayley/g' /tmp/*.txt sed -i 's/0724021236/Isaac-SNR/g' /tmp/*.txt sed -i 's/0724021236/Isaac-SNR/g' /tmp/*.txt sed -i 's/0730092023/Isaac-JNR/g' /tmp/*.txt sed -i 's/0730448205/Jaysen/g' /tmp/*.txt sed -i 's/0824874059/Jean/g' /tmp/*.txt sed -i 's/0827796158/Jerry/g' /tmp/*.txt sed -i 's/0743115570/Jimmy/g' /tmp/*.txt sed -i 's/0844541646/Jono/g' /tmp/*.txt sed -i 's/0823918640/Judy/g' /tmp/*.txt sed -i 's/0834585171/Lita/g' /tmp/*.txt sed -i 's/0726912960/Megan/g' /tmp/*.txt sed -i 's/0768511320/Sharon/g' /tmp/*.txt sed -i 's/0836687892/Solomon/g' /tmp/*.txt sed -i 's/0724340725/Sune/g' /tmp/*.txt sed -i 's/0782673693/Tiny/g' /tmp/*.txt sed -i 's/0114833051/10-2nd-Avenue-Houghton-Estate-(Pty)-Ltd/g' /tmp/*.txt sed -i 's/0116168348/123-Montessori/g' /tmp/*.txt sed -i 's/0114401561/180-DEGREES-PTY-LTD/g' /tmp/*.txt sed -i 's/0116567015/20-20-Insight/g' /tmp/*.txt sed -i 's/0114778718/321go-Travel-Consultants-CC/g' /tmp/*.txt sed -i 's/0114544439/7th-Element-Production/g' /tmp/*.txt sed -i 's/0113057242/@home/g' /tmp/*.txt sed -i 's/0123261978/A-&-A-Creations/g' /tmp/*.txt sed -i 's/0114554555/AA-Diamonds/g' /tmp/*.txt sed -i 's/0834694430/Abdul/g' /tmp/*.txt sed -i 's/0118131890/aBEErate-Verification-Agency/g' /tmp/*.txt sed -i 's/0119791885/Aboard-Refrigeration/g' /tmp/*.txt sed -i 's/0114543130/Above-&-Beyond-Concepts/g' /tmp/*.txt sed -i 's/0128038348/ABSOLUTE-DOORS/g' /tmp/*.txt sed -i 's/0114441019/Abu-Daya/g' /tmp/*.txt sed -i 's/0116800368/A Calisto-Portuguese-Restuarant/g' /tmp/*.txt sed -i 's/0119555200/ACAirConsupport/g' /tmp/*.txt sed -i 's/0117873571/ACCVANTAGESOLUTIONS/g' /tmp/*.txt sed -i 's/0110242178/ACRClothingManufacturers/g' /tmp/*.txt sed -i 's/0126536032/ActiveMotors/g' /tmp/*.txt an EG of the xls file Acc BRI005 Telephone: /0116253000 sed-i's/ CorporateServicesadivisionofBridge Fax: /0116253090 DeliveryAddress PostalAddress Contact: Feranah 1BridgeClose MobilePhone: CityDeep Email: Ext19 Type: O/I Category: 1 NormalTerms: 2 |
For the third time this thread...
*** USE CODE TAGS!! *** http://www.linuxquestions.org/questi...do=bbcode#code I'm not about to go parsing all of that to understand what you want at this point. But I will point out that you don't need a bunch of individual commands. All you need is a file that contains the expressions, one per line. Then you can run it all in a single command using the -f option. sedfile.txt Code:
s/074318520/Dorcas/g Code:
sed -i -f sedfile.txt /tmp/*.txt |
All times are GMT -5. The time now is 05:09 AM. |