Saturday, November 24, 2007

Naresh_creative

Hai Friends this is Naresh Babu PV , i Want be Innovative always ...


If any problem pls contact nareshss66@gmail.com
posted a problem here like this
1)take a text file like this

L: 1 * L: 2 * L: 3
CHINNA SATTI RAJU VIPPELLA CHINNA VEERAJU PALAKURTHI GOVINDA RAO MASINA
SAMRLAKOT P O SAMARLAKOT P O SAMRLAKOT P O
KAKINADA T Q KAKINADA T Q KAKINADA T Q
EAST GODAVARI(DT) EAST GODAVARI(DT) EAST GODAVARI (DT)
533440 533440 533440


L: 4 L: 5 L: 6 *
MALLAIAH CHOUDARY SARIPINENI GOPALA KRISHNAIAH PASALA GANGADHARA RAMA RAO CHOWDARY G
SAMRLAKOT P O SAMRLAKOTA (PO) M/S SURYA PRAKASH SERVICE STATION
KAKINADA T Q KAKINADA (TQ) LALACHERUVU
EAST GODAVARI (DT) EAST GODAVARI (DT) RAJMUNDRRY
533440 533440 533101

2) the above file contains 3 columns
3) make three columns to two(2) columns
4) with out changing the order
5) No modification of data
**************************************************
Problem solving
1) take the above data.txt file
2) find out every address field started at same colum numbering like this
a) first columns(0 to 41)
b) second columns(41 to 78)
c)3rd columns(79 onwards)
3) then cutting the data file into 3 patrs like this

LINUX TERMINAL
*****************

cut -c-41 data.txt > x1.txt
cut -c42-78 data.txt > x2.txt
cut -c79- data.txt > x3.txt


output Example

L: 1 *
CHINNA SATTI RAJU VIPPELLA
SAMRLAKOT P O
KAKINADA T Q
EAST GODAVARI(DT)
533440


L: 4
MALLAIAH CHOUDARY SARIPINENI
SAMRLAKOT P O
KAKINADA T Q
EAST GODAVARI (DT)
533440



L: 7 *
RANGA RAO BOLLA
P AGRAHARM
RAJOLU (TQ)
EAST GODAWARY (DT)



L: 10
RAMA DAS KARUTURI
M/S SWATANTRA AGENCIES
RAJAMANDRI P O
EAST GODAVARI (DT)


cut the file into columns wise use command "cut"

4)Above commands are used to cut the files into 3parts(columns).

5)Then the 3files are merge into single file then it looks like a single column


more x[123].txt
/* this is command is used for view the content of the 3 fles
merge into single file
cat x[123].txt
/* combine the 3files into single file .
cat x[123].txt | more
/* to view the file here x[123] indicates x1,x2,x3.


try this command u get it


/*| is used for merge the commands
/* more is used for the print the data
/* tr is used for translate \n to @ ...
/* sed is used for Stream editor
/* s is used for substitude the value
/* sort is used for sorting
/* g is used for globle declaration
/* -s is used for the sqez the spaces into single spaces

cat x[123].txt | tr '\n' '@' |sed 's/L: /\nL: /g' |tr -s ' ' |more


/* the merged file c[123].txt is changed like this tr(translate) \n(new line)
into @ then sed(steam editor) to s(subtitute) L: with \nL:
then g used for global declaration then tr(transulate) -s (squez)
spaces into single spaces.


cat x[123].txt | tr '\n' '@' |sed 's/L: /\nL: /g' |tr -s ' ' |sort

cat x[123].txt | tr '\n' '@' |sed 's/L: /\nL: /g' |tr -s ' ' |sed 's/@/ @/' |more

cat x[123].txt | tr '\n' '@' |sed 's/L: /\nL: /g' |tr -s ' ' |sed 's/@/ @/' |sort -t ' ' +1 -2 -n > xyz.txt

cat x[123].txt | tr '\n' '@' |sed 's/L: /\nL: /g' |tr -s ' ' |sed 's/@/ @/' |sort -t ' ' +1 -2 -n |more



upto here you get a single file like single column with sorting order file name is xyz.txt
         
Example output
L: 1 * @ CHINNA SATTI RAJU VIPPELLA @ SAMRLAKOT P O @ KAKINADA T Q @ EAST GODAVARI(DT) @ 533440 @@@
L: 2 * @ CHINNA VEERAJU PALAKURTHI @ SAMARLAKOT P O @ KAKINADA T Q @ EAST GODAVARI(DT) @ 533440 @@@
L: 3 @GOVINDA RAO MASINA@SAMRLAKOT P O@KAKINADA T Q@EAST GODAVARI (DT)@533440@@@
L: 4 @ MALLAIAH CHOUDARY SARIPINENI @ SAMRLAKOT P O @ KAKINADA T Q @ EAST GODAVARI (DT) @ 533440 @@@ @
L: 5 @ GOPALA KRISHNAIAH PASALA @ SAMRLAKOTA (PO) @ KAKINADA (TQ) @ EAST GODAVARI (DT) @ 533440 @@@
L: 6 * @GANGADHARA RAMA RAO CHOWDARY G@M/S SURYA PRAKASH SERVICE STATION@LALACHERUVU@RAJMUNDRRY@533101@@@
L: 7 * @ RANGA RAO BOLLA @ P AGRAHARM @ RAJOLU (TQ) @ EAST GODAWARY (DT) @@@ @
L: 8 @ THAMMI RAJU PATURI @ VELANGI P O @ KAKINADA T Q @ EAST GODAVARI (DT) @ 533260 @@@
L: 9 @SATYANARAYANA PUTTA@MANDAPET P O@R C PURAM T Q@EAST GODAVARI (DT)@533308@@@
L: 10 @ RAMA DAS KARUTURI @ M/S SWATANTRA AGENCIES @ RAJAMANDRI P O @ EAST GODAVARI (DT) @ @@
L: 11 @ VEERABHADRA RAO CHANDLADA @ SAMARLAKOTA P O @ KAKINADA T Q @ EAST GODAVARI (DT) @ 533440 @ @@

then write program for to display data into two columns by using any prgramming or scripting language
Iam using PHP program for solving this problem....
like this


<?php
$df=file($argv[1]);
$i=1;
$str="<table>";
foreach($df as $line) {
if($i%2) $str.="\n<tr>";
$address=explode("@",str_replace("\n","",$line));
$str.="<td>";
foreach($address as $field) {
$str.=$field."<br>";
}
$str.="</td>";
if($i%2) $str.="</tr>";
else
$str.="<tr><td> </td><td></td></tr>";
$i++;
}
$str.="</table>";
echo $str;
?>


Then save this file with:: formatdata.php



/* run the php use this syntex :php -q

php -q formatdata.php xyz.txt > xyz.html

/* out put is send to xyz.html

elinks xyz.html

/* elinks is used for the view the html form

elinks -dump xyz.html > reformatted_data.txt

/* dump is used to output the above xyz.html file into text file format
/* finally You get the reformated_data.txt in textformat..

this way You get the answer

if any problem pls contact to nareshss66@gmail.com
Thank you

3 comments:

SudheerKumar.N said...

thank you Naresh U done a great job ,It is help a lot for me .keep post blogs

SudheerKumar.N said...

Your Exellency Never Fails Mr....B'cos U r soooooooooooo Innovative

Venkata NareshBabu P said...

great ya naresh