Solved Shell script : I need to write script for this. pl help me

September 13, 2012 at 03:29:10
Specs: Linux x86_64
Shell script :
I need to remove C-P WEBOPTIN1 PostBrandedWebSubscription.java - , 4 ipx_de $NULL$ 4.99 and finally need to change this serial no 491629461544 to 4*********** and 1662028 to 1****** ... pl help me.... i need to write script for this..

script:
21-05-2012 15:03:30 C-P WEBOPTIN1 PostBrandedWebSubscription.java - OPT_1 Mon May 21 15:03:30 CEST 2012 1662028 491629461544 4 ipx_de $NULL$ 4.99 2.202.106.233 Mobilcom DE 26213 3G $NULL$ BRANDED MOBILE WEB SUBSCRIPTION
21-05-2012 15:03:31 C-P WEBOPTIN2 PostBrandedWebSubscription.java - OPT_2 Mon May 21 15:03:31 CEST 2012 1662028 491629461544 4 ipx_de wootube 4.99 2.202.106.233 Mobilcom DE 26213 3G $NULL$ BRANDED MOBILE WEB SUBSCRIPTION
I need to edit like below please help me
output:
21-05-2012 15:03:30 OPT_1 Mon May 21 15:03:30 CEST 2012 1****** 4*********** 2.202.106.233 Mobilcom DE 26213 3G $NULL$ BRANDED MOBILE WEB SUBSCRIPTION
21-05-2012 15:03:31 OPT_2 Mon May 21 15:03:31 CEST 2012 1****** 4*********** 2.202.106.233 Mobilcom DE 26213 3G $NULL$ BRANDED MOBILE WEB SUBSCRIPTION


See More: Shell script : I need to write script for this. pl help me

Report •

✔ Best Answer
September 14, 2012 at 00:02:38
This will do the whole thing:

sed -e 's/1662028/1******/g' -e 's/491629461544/4***********/g' -e 's/ C-P WEBOPTIN[1:2] PostBrandedWebSubscription.java -//g' -e 's/4 ipx_de.*4.99//g' datfile.txt



#1
September 13, 2012 at 05:38:28
Try this:

awk '{gsub(/1662028/,"1******") gsub(/491629461544/,"4***********")} {print >/filepath/newfile}' /filepath/script >/filepath/newfile


Report •

#2
September 13, 2012 at 09:39:04
Thank u .... how to cut the particular words from line.... i need to write script can u pls help me.....

Report •

#3
September 13, 2012 at 12:45:28
awk is a fine tool and so is sed - the stream editor. Here is an example where I do 2 of your 4 requirements. string the other two requirements together using the -e option:

#!/bin/bash

sed -e 's/1662028/1******/g' -e 's/4 ipx_de $NULL$ 4.99//' datafile.txt
# end script

Since you are using Linux, you can use the -i option which edits datafile.txt in place:

sed -i -e 's/1662028/1******/g' -e 's/4 ipx_de $NULL$ 4.99//' datafile.txt


Report •

Related Solutions

#4
September 13, 2012 at 21:01:06
Thank you..... But i cant cut this- '4 ipx_de $NULL$ 4.99' i have tried many times. please reply...

Report •

#5
September 13, 2012 at 21:05:42
awk '{print $1,$2,$7,$8,$9,$10,$11,$12,$13,$14,$15,$20,$21,$22,$23,$24,$25,$26,$27,$28,$29;}' file.txt
Instead of this please suggest me any other commands.. please

Report •

#6
September 13, 2012 at 22:31:36
I don't know what you are doing, but this command:

sed -e 's/1662028/1******/g' -e 's/4 ipx_de $NULL$ 4.99//' datafile.txt

replaces: 1662028 with: 1******

and

replaces: 4 ipx_de $NULL$ 4.99 with nothing

How about posting some code?

And I don't know what you are doing with that awk stub in #5?????


Report •

#7
September 13, 2012 at 22:53:38
its not replacing nothing....
By using this command

sed -e 's/1662028/1******/g' -e 's/4 ipx_de $NULL$ 4.99//' datafile.txt

1662028 changed to 1*******

but replacement not done 4 ipx_de $NULL$ 4.99 with nothing.. please reply


Report •

#8
September 13, 2012 at 23:00:23
okay...thank you it replaced.space was there. like this

4 ipx_de $NULL$ 4.99

i did...
How to write it in sricpt??
can u help me


Report •

#9
September 13, 2012 at 23:09:31
okay...thank you so much it replaced.space was there. like this

4 ipx_de $NULL$ 4.99

its came now... thank you...

How to write it in sricpt??
can u help me


Report •

#10
September 14, 2012 at 00:02:38
✔ Best Answer
This will do the whole thing:

sed -e 's/1662028/1******/g' -e 's/491629461544/4***********/g' -e 's/ C-P WEBOPTIN[1:2] PostBrandedWebSubscription.java -//g' -e 's/4 ipx_de.*4.99//g' datfile.txt


Report •

#11
September 14, 2012 at 00:27:15
Thank you paul.....

how to write this in script.
As i begineer to shell script... i don no which loop need to use,,, i have no idea.. please help me...


Report •

#12
September 14, 2012 at 00:44:33
Script looks like this:

---SNIP---

#!/bin/bash
# Script to modify /filepath/datfile.txt
#
sed -e 's/1662028/1******/g' -e 's/491629461544/4***********/g' -e 's/ C-P WEBOPTIN[1:2] PostBrandedWebSubscription.java -//g' -e 's/4 ipx_de.*4.99//g' datfile.txt

---SNIP---


Report •

#13
September 14, 2012 at 01:47:32
Thank you so much

i want to know another command.. pl
without mentioning these text is there any command to remove .because these below text will be not same for all files. text will change for another file but fields are same.

C-P WEBOPTIN[1:2] PostBrandedWebSubscription.java
4 ipx_de.*4.99
can u help me


Report •

#14
September 14, 2012 at 02:08:04
Could you post an example of the other files and what has to be replaces or removed?

Report •

#15
September 14, 2012 at 02:29:18
17-07-2011 11:00:40 L-H APPOPTIN1 ExtendedAppSubscription.java - OPT_1 FRI Marcj 10 18:30:20 CEST 2011 7282718 491705041668 4 ipx_de APP 8.55 2.203.107.233 Telpho ES 42168 3G $NULL$ BRANDED TELPHO APP SUBSCRIPTION

From above i need cut L-H APPOPTIN1 ExtendedAppSubscription.java - and 4 ipx_de APP 8.55 and 7282718 to 7******* and 491705041668 to 4***********

so if i run the script.... these fileds need to remove. If i using text in script i need to write script for another file.
help me


Report •

#16
September 14, 2012 at 04:57:07
can you help me...????

Report •

#17
September 14, 2012 at 09:00:46
#12 should give you an idea on how to create another script, to do the job for the other files, where you have to make changes to.

You simply have to exchange the strings for your needs.


Report •

Ask Question