Solved

**** Shell script *****

Posted on 2002-07-29
10
291 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

828 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