Dear Alll
I have 16 columns,in my data file.In my 16th column i m getting unwanted data like /186.how to remove it.The value in 16th column is dynamic.
Data:
-----
25|1059530000|9305282846|355780600|100|1|0|4:UPE0|241|1|4121|2|0|100|100|14655/186
25|1059530001|9305282847|355780670|100|2|0|4:UPE0|241|1|4121|2|0|100|100|14655/184
8728|2040701618|9358642959|332661308|100|0|0|4:UPW0|243|1|4616|2|0|100|100|0/0
8728|2040701617|9358642958|332661253|100|2|0|4:UPW0|243|1|4616|2|2|100|100|14655/191
Thus i want to remove those Bolded data from the line.My output should be as follows.
25|1059530000|9305282846|355780600|100|1|0|4:UPE0|241|1|4121|2|0|100|100|14655
25|1059530001|9305282847|355780670|100|2|0|4:UPE0|241|1|4121|2|0|100|100|14655
8728|2040701618|9358642959|332661308|100|0|0|4:UPW0|243|1|4616|2|0|100|100|0
8728|2040701617|9358642958|332661253|100|2|0|4:UPW0|243|1|4616|2|2|100|100|14655
can i do this in sed or awk.The error is only in 16th column.records to be deleted 10 million.
sed 's:/.*::' input_file > output_file
Can u just explain why u r using .*::.
or just tel whether it is replacing all the charecters after / or it is deleting .
The 'sed' command 's:/.*::' removes from all lines strings that begin with '/'.
sed 's#\(.*\)|.*/.*$#\1#' myFile
Vgersh,
Your solution removed the last field entirely including the vertical bar '|'.
See the output for the sample data given by the OP:
25|1050000|9305282846|355780600|100|1|0|4:UPE0|241|1|4121|2|0|100|100
25|1050001|9305282847|355780670|100|2|0|4:UPE0|241|1|4121|2|0|100|100
8728|2701618|9358642959|332661308|100|0|0|4:UPW0|243|1|4616|2|0|100|100
8728|201617|9358642958|332661253|100|2|0|4:UPW0|243|1|4616|2|2|100|100
Incase if my data contains a address field as follows..
0|6799834|3/4,FirstMain road,Mumbai/Maharashtra|789898|0/787
then how i will remove the last /787 only.In case of
sed 's:/.*::' input_file > output_file
it would remove all charecters form /4,FirstMain road,Mumbai/Maharashtra|789898|0/787
Correct me if i am wrong
.Thanx
shell_life:
Vgersh,
Your solution removed the last field entirely including the vertical bar '|'.
See the output for the sample data given by the OP:
25|1050000|9305282846|355780600|100|1|0|4:UPE0|241|1|4121|2|0|100|100
25|1050001|9305282847|355780670|100|2|0|4:UPE0|241|1|4121|2|0|100|100
8728|2701618|9358642959|332661308|100|0|0|4:UPW0|243|1|4616|2|0|100|100
8728|201617|9358642958|332661253|100|2|0|4:UPW0|243|1|4616|2|2|100|100
sorry - misread the OP's requirement.
tkbharani:
Incase if my data contains a address field as follows..
0|6799834|3/4,FirstMain road,Mumbai/Maharashtra|789898|0/787
then how i will remove the last /787 only.In case of
sed 's:/.*::' input_file > output_file
it would remove all charecters form /4,FirstMain road,Mumbai/Maharashtra|789898|0/787
Correct me if i am wrong
.Thanx
Tkbharani,
One of the most important rules when asking to solve a problem is
to give all pertinent details of the problem.
I gave a solution based on your sample data.
You asked for a plain burger and now you want it with mustard, mayonese,
french fries and milkshake.
sed 's:/[0-9]\{1,3\}$::' input_file
shell_life:
Tkbharani,
One of the most important rules when asking to solve a problem is
to give all pertinent details of the problem.
I gave a solution based on your sample data.
You asked for a plain burger and now you want it with mustard, mayonese,
french fries and milkshake.
ok..ok...its just some Curiosity yar. Now pls can u give me some mustard, mayonese,
french fries and milkshake. I am in need of it...yar
I'm also interested in this solution.
I could do this using awk but could not do the same in sed.
My interest in this solution is purely academical ( I don't have 10 million records to parse )
Any solution??
kahuna
July 27, 2007, 7:59am
13
Assuming the data does not contain "~", how about?
sed 's/|/~/15;s:~\([^|/]*\)/\{0,1\}[^|]*:|\1:'
I'm curious, how do you do it in awk?