The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Changing from Excel date format to MySQL date format figaro UNIX for Dummies Questions & Answers 2 08-11-2009 04:23 PM
changing month in Mmm format to mm FORMAT RahulJoshi Shell Programming and Scripting 1 09-04-2008 03:20 AM
Getting month and changing format marringi UNIX for Dummies Questions & Answers 7 05-19-2008 03:42 PM
changing format shary Shell Programming and Scripting 4 01-31-2008 05:20 AM
changing the format of date nasirgondal Post Here to Contact Site Administrators and Moderators 1 06-08-2006 02:37 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 4 Weeks Ago
kartheek kartheek is offline
Registered User
  
 

Join Date: Nov 2009
Posts: 4
changing all the lines in one format

Hi,

I am beginner. have almost one text file which contains 6000 lines. every line is in different format.so need to rearrange in single format.

Ex: .thde.adgtmk.802ati
thde.kghijk..567ati
..thde.kghijk..458ati
thde.ertyui.456.567.789ati
thde.awse.dati

Rules:
1.no line should start with '.' or '..'
2.if line contains more 11characters then need add one space after that(if 12th character is '.' then need replace with one space other wise add one space)
3.if 12th and 13th both are '.' then replace with one space.
4.if line contains like - thde.ertyui.456.567.789ati

then need to replace like
thde.ertyui 456ati
thde.ertyui 567ati
thde.ertyui 789ati

5.if line contains - thde.awse.dati
then thde.awse dati
every line should contain 11character then either '.' or '..'
if line have 4 characters then '.' then 5 characters so totally 10 characters only have then 11 character has to insert as space.

so finally output should appear like

thde.adgtmk 802ati
thde.kghijk 567ati
thde.kghijk 458ati
thde.ertyui 456ati
thde.ertyui 567ati
thde.ertyui 789ati
thde.awse dati

It would be great if i get the solution ASAP
Thanks a lot...

---------- Post updated at 08:17 PM ---------- Previous update was at 05:08 PM ----------

I am using AIX/unix.....if it could done with AWK and SED .....really it would be great....
  #2 (permalink)  
Old 4 Weeks Ago
durden_tyler's Avatar
durden_tyler durden_tyler is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2009
Posts: 552

Code:
$
$ cat f1.in
.thde.adgtmk.802ati
thde.kghijk..567ati
..thde.kghijk..458ati
thde.ertyui.456.567.789ati
thde.awse.dati
$
$ ##
$ perl -lne 's/^\.{1,2}//;
>   if (/^(\w{4}\.\w{4,6})\.+(\w+)$/) {$_ = "$1 $2"}
>   elsif (/^(\D+)\.(\d+)\.(\d+)\.(\d+)(\D+)$/) {$_ = "$1 $2$5\n$1 $3$5\n$1 $4$5"}
>   print' f1.in
thde.adgtmk 802ati
thde.kghijk 567ati
thde.kghijk 458ati
thde.ertyui 456ati
thde.ertyui 567ati
thde.ertyui 789ati
thde.awse dati
$
$

tyler_durden
  #3 (permalink)  
Old 3 Weeks Ago
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,092

Code:
while(<DATA>){
	chomp;
	s/^\.*//;
	if(/thde.awse.dati/){
		print $_,"\n";
	}
	elsif(/^(.{11})\.+([^.]+$)/){
		print $1," ",$2,"\n";
	}
	else{
		my @tmp=split("[.]",$_);
		my @t1=split(/(?=[^0-9]*$)/,$tmp[$#tmp],2);
		my @final=(@tmp[2..$#tmp-1],$t1[0]);
		my $suffix=$t1[1];
		map {print $tmp[0],".",$tmp[1]," ",$_,$suffix,"\n"} @final;
	}
}
__DATA__
.thde.adgtmk.802ati
thde.kghijk..567ati
..thde.kghijk..458ati
thde.ertyui.456.567.789ati
thde.awse.dati

Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:56 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0