Solved

**** Shell script *****

Posted on 2002-07-29
10
288 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
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
 
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Currently, there is not an RPM package available under the RHEL/Fedora/CentOS distributions that gives you a quick and easy way to allow PHP to interface with Oracle. As a result, I have included a set of instructions on how to do this with minimal …
I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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.

708 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now