Solved

**** Shell script *****

Posted on 2002-07-29
10
294 Views
Last Modified: 2013-12-16
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
Comment
Question by:mahanteshs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 3

Accepted Solution

by:
DVB earned 34 total points
ID: 7185508
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
 
LVL 51

Assisted Solution

by:ahoffmann
ahoffmann earned 33 total points
ID: 7186525
tr '[ ,;]' '\012' <file|egrep -v '^$'
0
 
LVL 20

Assisted Solution

by:Gns
Gns earned 33 total points
ID: 7196434
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
Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

 
LVL 20

Expert Comment

by:Gns
ID: 7196447
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
 
LVL 20

Expert Comment

by:Gns
ID: 8648055
(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
 

Expert Comment

by:CleanupPing
ID: 9076974
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
 
LVL 1

Expert Comment

by:drewber
ID: 9220391
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
 
LVL 20

Expert Comment

by:Gns
ID: 9222075
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
 
LVL 12

Expert Comment

by:paullamhkg
ID: 10389837
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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question