Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 300
  • Last Modified:

**** Shell script *****

Hello,

I have a file dummy.log, its content is

300%%%%800 200%%%%987 345%%%%987
123%%%%098,200%%%%876 890%%%%8976
876,1908%%%%0987, 100091%%%%389765
12387%%%%098; 2001%%%%876;85690%%%%812976    

Now I want to create a new file dummy1.log based on the contents of this file

dummy1.log should be

300%%%%800
200%%%%987
345%%%%987
123%%%%098
200%%%%876
890%%%%8976
1908%%%%0987
100091%%%%389765
12387%%%%098
2001%%%%876
85690%%%%812976    

Please suggest me how to do this?
Any sed or awk commands I can use?

(My basic idea is to find strings those match a regular pattern from a file and write those strings to a new file one at a time)

thank U in advance
mahantesh.
0
mahanteshs
Asked:
mahanteshs
3 Solutions
 
DVBCommented:
Does this have to be sed/awk/shell? Or can you use Perl?
Perl would be much easier for implementing this.
#!/usr/bin/perl -w
use strict;

while(<>)
{
 my ($first,$second,$third) = split(/ ,;/,$_);
 print "$first\n$second\n$third\n);
}

Takes log on stdin, and writes to stdout.

(Should work, otherwise itt will spew a ton of errors)
0
 
ahoffmannCommented:
tr '[ ,;]' '\012' <file|egrep -v '^$'
0
 
GnsCommented:
Elegant, ahoffman.

DVB: What happens when there is a fourth string split off the line?
You should have used an array something like:
...
@gurp = split(/ ,;/,$_);
print join("\n",@gurp);
undef(@gurp);
...

or similarily

while(<>)
{
@gurp = split(/ ,;/,$_);
}
print join("\n",@gurp);

or if awk is the prefered tool

awk '{gsub(/[ ,;]/,"\n");print;}'<file

or sed (no this isn't a typo, its suposed to be a newline after the backslash, to facilitate a newline being substituted)

sed 's/[ ,;]/\
/g' < file

or

sed 'y/ .;/\
\
\
/' < file

-- Glenn
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
GnsCommented:
Ooops, add the egrep from ahoffmanns example to all my examples (time to go home...way to befuddled to do any serious work:-)

-- Glenn
0
 
GnsCommented:
(10 months later...) Lots of simple suggestions... so .... which did you end up using mahantesh?

-- Glenn (Who is going through the "real-old-unlocked-questions" he has commented in)
0
 
CleanupPingCommented:
mahanteshs:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
drewberCommented:
This question has been classified abandoned. I will make a recommendation to the moderators on its resolution in a week or two. I appreciate any comments that would help me to make a recommendation.
 

Unless it is clear to me that the question has been answered I will recommend delete. It is possible that a Grade less than A will be given if no expert makes a case for an A grade. It is assumed that any participant not responding to this request is no longer interested in its final disposition.

 
If the user does not know how to close the question, the options are here:
http://www.experts-exchange.com/help/closing.jsp
 
drewber
0
 
GnsCommented:
Points to ahoffmann, possibly a split with 70-30 with DVB... I just got carried away "improving" DVBs comment (and providing the equivalent awk and sed:-).

-- Glenn
0
 
paullamhkgCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Split: DVB {http:#7185508} & ahoffmann {http:#7186525} & Gns {http:#7196434}

Please leave any comments here within the next four days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

paullamhkg
EE Cleanup Volunteer
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now