changing all the lines in one format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting changing all the lines in one format
# 1  
Old 11-07-2009
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 Smilie
Thanks a lot...Smilie

---------- 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.... Smilie
# 2  
Old 11-07-2009
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  
Old 11-08-2009
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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Changing the file name format

Hello all, I am tryign to change the format of files (which are many in numbers). They at present are named like this: SomeProcess_M-130_100_1_3BR.root SomeProcess_M-130_101_2_3BX.root SomeProcess_M-130_103_3_3RY.root SomeProcess_M-130_105_1_3GH.root SomeProcess_M-130_99_1_3LF.root... (7 Replies)
Discussion started by: emily
7 Replies

2. Shell Programming and Scripting

Changing date format

how do i change the following to show me what the date was 7 days ago? date +%Y-%m-%d (1 Reply)
Discussion started by: SkySmart
1 Replies

3. Shell Programming and Scripting

Changing Date Format

How can i make the date command output yesterday's date, current date and the date 4 days ago, in the following format: 2012-10-03 code: date +% ???? (3 Replies)
Discussion started by: SkySmart
3 Replies

4. Shell Programming and Scripting

Changing the date format

Hi all, I have a file with below data af23b|11-FEB-12|acc7 ad23b|12-JAN-12|acc4 as23b|15-DEC-11|acc5 z123b|18-FEB-12|acc1 I need the output as below:-(date in yyyymmdd format) af23b|20120211|acc7 ad23b|20120112|acc4 as23b|20111215|acc5 z123b|20120218|acc1 Please help me on this.... (7 Replies)
Discussion started by: gani_85
7 Replies

5. Shell Programming and Scripting

changing the format of the list

I have a file such that List : a, b, c, d I want to list this as List a b c d however the trick is the number of arguments in the list is varies. There might be 0-7 variables . Can you help me? Please use code tags when posting data and code samples! (5 Replies)
Discussion started by: ozum
5 Replies

6. UNIX for Dummies Questions & Answers

Changing from Excel date format to MySQL date format

I have a list of dates in the following format: mm/dd/yyyy and want to change these to the MySQL standard format: yyyy-mm-dd. The dates in the original file may or may not be zero padded, so April is sometimes "04" and other times simply "4". This is what I use to change the format: sed -i '' -e... (2 Replies)
Discussion started by: figaro
2 Replies

7. Shell Programming and Scripting

changing month in Mmm format to mm FORMAT

i have an variable mydate=2008Nov07 i want o/p as in variable mymonth=11 (i.e nov comes on 11 number month) i want some command to do this for any month without using any loop. plz help me (1 Reply)
Discussion started by: RahulJoshi
1 Replies

8. Shell Programming and Scripting

changing format

Dear Experts, Currently my script is gereating the output like this as mentioned below. 8718,8718,0,8777 7450,7450,0,7483 5063,5063,0,5091 3840,3840,0,3855 3129,3129,0,3142 2400,2400,0,2419 2597,2597,0,2604 3055,3055,0,3078 4249,4249,0,4266 4927,4927,0,4957 8920,8920,0,8978... (4 Replies)
Discussion started by: shary
4 Replies

9. Post Here to Contact Site Administrators and Moderators

changing the format of date

In my shell script i have a variable which stores date in the format of YYYYMMDD. Is there any way to format this value to MM/DD/YYYY. Thanks. (1 Reply)
Discussion started by: nasirgondal
1 Replies

10. Shell Programming and Scripting

Changing the date format

Hi, I know there is a Q/A section and lots of posts regarding date command here. I am sorry to start a new thread. I am very new to shell scripting (actually i am working on my first program), so please forgive my ignorance. I could not find an answer to my problem else where so i posted it... (10 Replies)
Discussion started by: Dream86
10 Replies
Login or Register to Ask a Question