![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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.... ![]() |
|
||||
|
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
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|