ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Help us to help you. Give us a sample input file (at least 10-12 lines). Construct a sample output file which corresponds to your sample input and post both samples here. With "Before and After" examples we can better understand your needs and also judge if our proposed solution fills those needs.
It is almost certain that sed or grep will do the job.
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
Notice that you can use any basic ascii character as the s delimiter, so just choose one that's not found in the expression itself. I used "_" in the above.
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
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
This is not what you need it to look like. This is a list of sed commands, which may or may not produce the desired output.
So firstly, please use [code][/code] tags around your code and data.
Secondly, show the actual desired output required.
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
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
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.