Solved

**** Shell script *****

Posted on 2002-07-29
10
292 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
When trying to install php-fpm on CentOS 7 - GPG error 2 130
Can't connect to FTP 18 149
Windows 10 linux VM 30 91
SSSD - Automatic kerberos ticket initialization 1 38
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.…
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
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.:
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

738 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