convertion of a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting convertion of a file
# 1  
Old 02-14-2009
convertion of a file

Hi

I am having file like this


1 560017039 575052020 22-11-2003 8,290.00 709545 100239050 11
2 560017006 575052020 13-01-2008 20,000.00 709545 100246770 11

i want to convert it like

5600170395750520202211200300000008290000000000000709545010023905011
5600170065750520201301200800000020000000000000000709545010024677011

pls help
# 2  
Old 02-14-2009
And the conversion rules would be...?
# 3  
Old 02-14-2009
Try this one.
Code:
awk '{gsub("-","",$4);gsub("[,|.]","",$5);printf "%s%013d%016d%010d%s\n",$2$3$4,$5,$6,$7,$8}' file

Use GNU awk (gawk), New awk (nawk) or POSIX awk (/usr/xpg4/bin/awk).

Last edited by danmero; 02-15-2009 at 10:19 AM.. Reason: Add note
# 4  
Old 02-14-2009
Suppose this is your data

Code:
[ahamed@localhost general]$ cat data2
1 560017039 575052020 22-11-2003 8,290.00 709545 100239050 11 
2 560017006 575052020 13-01-2008 20,000.00 709545 100246770 11

Here is the code:
Code:
#! /usr/bin/perl
use warnings;

open (DATAFILE, "<data2") or die $!;while (<DATAFILE>){
        my ($line) = $_;
       
        $line =~ s/(\s)|(\-)|(\.)|(\,)//g;
        $line =~ s/^(\S)//g;
        print $line;
        print "\n";
}


Code:
[ahamed@localhost general]$ ./data2.pl 
5600170395750520202211200382900070954510023905011
56001700657505202013012008200000070954510024677011

[ahamed@localhost general]$


Thanks
Ahamed Shameer
netgiz.net

Last edited by esham; 02-14-2009 at 02:58 PM..
# 5  
Old 02-14-2009
@Ahamed
  1. Use [code] tags , not [quote] tags. You can edit your post and change the tags.
  2. Check the original requested output. Your output don't match.
# 6  
Old 02-14-2009
Try this perl code:

Code:
#! /usr/bin/perl
use warnings;

open (DATAFILE, "<data2") or die $!;
while (<DATAFILE>){

        my ($line) = $_;
        $line =~ s/^(\S)|(\-)|(\.)|(\,)//g;
        $line =~ s/^(\s)//g;
        my ($var1, $var2, $var3, $fourthdata, $fifthdata, $var6, $var7) = split(/\s/, $line);
        $fourthdata = sprintf('%013d',$fourthdata);
        $fifthdata = sprintf('%016d',$fifthdata);
        print "$var1$var2$var3$fourthdata$fifthdata$var6$var7\n";
}

# 7  
Old 02-14-2009
Hi,
Just open the file with vi:
vi test.txt
:%s/ //g # remove space
:%s/-//g # remove -
:%s/,//g # remove ,
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script (sh file) logic to compare contents of one file with another file and output to file

Shell script logic Hi I have 2 input files like with file 1 content as (file1) "BRGTEST-242" a.txt "BRGTEST-240" a.txt "BRGTEST-219" e.txt File 2 contents as fle(2) "BRGTEST-244" a.txt "BRGTEST-244" b.txt "BRGTEST-231" c.txt "BRGTEST-231" d.txt "BRGTEST-221" e.txt I want to get... (22 Replies)
Discussion started by: pottic
22 Replies

2. Shell Programming and Scripting

Perl script database date convertion

Need assistance Below script get the output correctly I want to convert the date format .Below is the output . Any idea ? #!/usr/bin/perl -w use DBI; # Get a database handle by connecting to the database my $db = DBI->connect(... (3 Replies)
Discussion started by: ajayram_arya
3 Replies

3. Shell Programming and Scripting

Match list of strings in File A and compare with File B, C and write to a output file in CSV format

Hi Friends, I'm a great fan of this forum... it has helped me tone my skills in shell scripting. I have a challenge here, which I'm sure you guys would help me in achieving... File A has a list of job ids and I need to compare this with the File B (*.log) and File C (extend *.log) and copy... (6 Replies)
Discussion started by: asnandhakumar
6 Replies

4. Shell Programming and Scripting

Convertion from Exponential to Decimal

I am trying to read values from excel and perform some calculations but I am getting below error: expr 2.326227180240883E7 / 8.509366417956961E8 expr: non-numeric argument Can anyone let me know how do i convert thse exponential numbers to decimal. (2 Replies)
Discussion started by: sachinnayyar
2 Replies

5. Shell Programming and Scripting

Convertion of Date Format using SQL query in a shell script

When I write Select date_field from TableA fetch first row only I am getting the output as 09/25/2009. I want to get the output in the below format 2009-09-25 i.e., MM-DD-YYYY. Please help (7 Replies)
Discussion started by: dinesh1985
7 Replies

6. Shell Programming and Scripting

3 columns to 10 columns convertion

I have a file with three columns and I want to convert it to a 10 colum file i try thinks similar to awk '{printf "%8s%8s%8s",$1,$2,$3;if ( NR%4 == 0) print ""}' input > output but in this case doesn´t work because 10/3 = not an integer (excuse my non-native english) and thanks in... (4 Replies)
Discussion started by: aloctavodia
4 Replies

7. Shell Programming and Scripting

Hex to Decimal Convertion

Dear all, I have a file like this. EE48 4473 7FC9 EE48 102C D23 EE48 4DD 27D EE48 0 0 EE48 3FFE 854 F230 DC6 ... (1 Reply)
Discussion started by: Nayanajith
1 Replies

8. UNIX for Dummies Questions & Answers

Character Convertion Help Needed

Could someone please tell me how to convert double byte charaters to single byte characters in HP-UX 11.11 without installing any applications? e.g. I have a double byte string below and I want to convert it to a single byte string ABCdef123 ABCdef123 I tried using the iconv command but I... (3 Replies)
Discussion started by: stevefox
3 Replies

9. Filesystems, Disks and Memory

convertion

How to convert a .doc document to .pdf (2 Replies)
Discussion started by: areef4u
2 Replies

10. Shell Programming and Scripting

ASCII to char convertion

I am writing the script to encrypt and decrypt content of the text file. How can I convert ASCII to characters and backward? I need it for Bourne shell script. Thanks::confused: (3 Replies)
Discussion started by: woody
3 Replies
Login or Register to Ask a Question