File format issue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File format issue
# 1  
Old 06-12-2013
File format issue

Hi All,

In unix is there any command to format the file in exact order.I have a file which there is no order in the fileds, I need to order it. Its a dat file

wrong format

Code:
TDEAIG36533827CB1210004241     EUR20130610BL1300351 refers to                     CB|CCI|A|A|C|R|T 246.76             0                0                0                0                0                0                0               1              000                                                   AS                             
 DEAIG36533827CB1210004241    10999999EUR20130610BL1300351 refers to 650A051012935         0                10GMVN5994A0                39.4             384              207.36           0                0                0               1      RL  DE  0747319319BL1300351 refers to 650A051012935   P0MGE0                                        DS
TDEAIG36075564CB1210004242     USD20130611040212BUD#1                    CB|CCI|A|A|C|R|T 0                  0                0                0                0                0                0                0               178            000                                                   AS                                      
 DEAIG36075564CB1210004242    10999999USD20130611040212BUD#1650A051011149         0                6gQ173BH0                0                0                0                0                0                0               2      53  DE  0426354354040212BUD#1650A051011149   P0USAg                                        DS           
 DEAIG36075564CB1210004242    10999999USD20130611040212BUD#1650A051011149         0                6zaaQA02505AB0                0                1450             0                0                0                0               2      53  DE  0426354354040212BUD#1650A051011149   P0USAzaa                                        DS    
 DEAIG36075564CB1210004242    10999999USD20130611040212BUD#1650A051011149         0                7hQ173BH0                0                0                0                0                0                0               4      53  DE  0426354354040212BUD#1650A051011149   P0USAh                                        DS           
 DEAIG36075564CB1210004242    10999999USD20130611040212BUD#1650A051011149         0                7eH46BG0                0                0                0                0                0                0               4      53  DE  0426354354040212BUD#1650A051011149   P0USAe                                        DS            
 DEAIG36075564CB1210004242    10999999USD20130611040212BUD#1650A051011149         0                6lQ697AJ0                0                0                0                0                0                0               2      53  DE  0426354354040212BUD#1650A051011149   P0USAl                                        DS           
 DEAIG36075564CB1210004242    10999999USD20130611040212BUD#1650A051011149         0                6pQ947BF0                0                0                0                0                0                0



Correct format

Code:
TDEAIG36533827CB1210004241                                          EUR20130610BL1300351 refers to                     CB|CCI|A|A|C|R|T              246.76                                          0                0                0                0                0                0                0                             1                     000                                                                                                                            AS
 DEAIG36533827CB1210004241                                10999999  EUR20130610BL1300351 refers to 650A051012935                                     0                10     GMVN5994A               0                39.4             384              207.36           0                0                0                             1      RL  DE  0747319319BL1300351 refers to 650A051012935                                   P0MGE0                                                  DS
TDEAIG36075564CB1210004242                                          USD20130611040212BUD#1                             CB|CCI|A|A|C|R|T              0                                               0                0                0                0                0                0                0                             178                   000                                                                                                                            AS
 DEAIG36075564CB1210004242                                10999999  USD20130611040212BUD#1         650A051011149                                     0                60     H52QDH9PW7AN            0                0                1050             0                0                0                0                             2      53  DE  0426354354040212BUD#1         650A051011149                                   P0USA0                                                  DS
 DEAIG36075564CB1210004242                                10999999  USD20130611040212BUD#1         650A051011149                                     0                6h     Q360GL                  0                0                0                0                0                0                0                             2      53  DE  0426354354040212BUD#1         650A051011149                                   P0USAh                                                  DS
 DEAIG36075564CB1210004242                                10999999  USD20130611040212BUD#1         650A051011149                                     0                6w     QA01375AF               0                0                0                0                0                0                0                             2      53  DE  0426354354040212BUD#1         650A051011149                                   P0USAw                                                  DS
 DEAIG36075564CB1210004242                                10999999  USD20130611040212BUD#1         650A051011149                                     0                6a     G996BA                  0                0                0                0                0                0                0                             2      53  DE  0426354354040212BUD#1         650A051011149                                   P0USAa                                                  DS
 DEAIG36075564CB1210004242                                10999999  USD20130611040212BUD#1         650A051011149                                     0                6e     H46BG                   0                0                0                0                0                0                0                             2      53  DE  0426354354040212BUD#1         650A051011149                                   P0USAe                                                  DS
 DEAIG36075564CB1210004242                                10999999  USD20130611040212BUD#1         650A051011149                                     0                6s     QA00782AF               0                0                100              0                0                0                0                             2      53  DE  0426354354040212BUD#1         650A051011149                                   P0US


You can observe the zero and other fields are in order in correct format
# 2  
Old 06-12-2013
You could use 'substring' in a shell script; Read in file and write it out in format you desire, simple example:
Code:
IFS="---"
while read line
do 
 f1=${line:0:1}
 f2=${line:1:25}
 echo "field 1: $f1"
 echo "field 2: $f2"
done < t

Code:
$ test.sh
field 1: T
field 2: DEAIG36533827CB1210004241
field 1:
field 2: DEAIG36533827CB1210004241
field 1: T
field 2: DEAIG36075564CB1210004242
field 1:
field 2: DEAIG36075564CB1210004242
field 1:
field 2: DEAIG36075564CB1210004242
field 1:
field 2: DEAIG36075564CB1210004242
field 1:
field 2: DEAIG36075564CB1210004242
field 1:
field 2: DEAIG36075564CB1210004242
field 1:
field 2: DEAIG36075564CB1210004242

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Issue with emailing format from UNIX

Need help as to why when I try email the following it does not come out right: DateOt=`date +"%a %b %d %T %Y"` TimeOt=`date +%H:%M:%S` interval=`cat $SecDiff| awk '{print $3}'` PortInReq2=`cat /shared/ftpdir/tools/quelog/logs/quelog.NPS_TO_SMG.log | grep PQI | wc -l` PortInRes2=`cat... (2 Replies)
Discussion started by: mrn6430
2 Replies

2. Shell Programming and Scripting

File read format issue in UNIX

hi all. my loop is getting failed eventhoug it is 1=1 but it is failure message. any help plz Output expected : echo "sucesss" code out=`cat bit.txt` if ]; then echo "sucess" else echo "Failure" (2 Replies)
Discussion started by: arun888
2 Replies

3. UNIX for Dummies Questions & Answers

Format issue

I was trying to copy the file content of program from server to other server you ctrl+c. once after the pasting in the other server the file alignment is getting changed. since I don't have scp permission. I am getting aligment improperly. wat needs to be done to make the format ccorrecltly as... (5 Replies)
Discussion started by: k.keerthi2005
5 Replies

4. Shell Programming and Scripting

Perl format issue

Input : day :15 and count -100 printf ("%6.6ld %10.10s %s\n",day,count) any idea what would be the format it will be. (3 Replies)
Discussion started by: ramkumar15
3 Replies

5. Shell Programming and Scripting

Issue with unrecognized zip format

Hi Friend, i have tried to generated zip file and received with attached mail by. But attachment file is unrecognized format not zip file by crontab, which is not able open. but there is no issue when the script is ran manually but i have received zip format. i am appriciate for your... (9 Replies)
Discussion started by: Jewel
9 Replies

6. Shell Programming and Scripting

to replace Date format issue

Hi, I have the below data in a file in one of the path, 101 02100002111406893401207310900A094101xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 5200xxxxxxxxxx D18000_1 CCDXXXXXXX JUL 31201207 1140689340000001 622113010547999999999003 000333333334RE ... (1 Reply)
Discussion started by: Ramyajiguru1
1 Replies

7. Shell Programming and Scripting

Format output issue

Dear Friends, Need your help. $cat input.txt TITLE Date:01-01-2011 Day: Friday Details Particulares Qty $ $ $ $ $ $more test.sh cat input.txt | while read line do echo "${line}" done $ $ (5 Replies)
Discussion started by: anushree.a
5 Replies

8. Shell Programming and Scripting

Converting windows format file to unix format using script

Hi, I am having couple of files which i used to copy from windows to Linux, so now in case of text files (CTRL^M) appears at end of line. I know i can convert this windows format file to unix format file by running dos2unix. My requirement here is that i want to do it automatically using a... (5 Replies)
Discussion started by: sarbjit
5 Replies

9. UNIX for Dummies Questions & Answers

To convert multi format file to a readable ascii format

Hi I have a file which has ascii , binary, binary decimal coded,decimal & hexadecimal data with lot of special characters (like öƒ.ƒ.„İİ¡Š·œƒ.„İİ¡Š· ) in it. I want to standardize the file into ASCII format & later use that as source . Can any one suggest a way a logic to convert such... (5 Replies)
Discussion started by: gaur.deepti
5 Replies

10. UNIX for Dummies Questions & Answers

File Format issue: Output of sqlplus

Hi, I am using a query like below in my shell script : { { echo "set echo off" echo "set head off" echo "whenever sqlerror exit -1; select NUMBER ||','|| FNAME ||','|| LOC ||','|| ... (2 Replies)
Discussion started by: deepakgang
2 Replies
Login or Register to Ask a Question