formate file in unix


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers formate file in unix
# 1  
Old 04-30-2008
formate file in unix

my file looks like this:
D8511049777 I 04/10/08 99817 1,923.33 927156 Kaufman
D8511049777I04100829981859003924884Martin


i'd like to look like this:
D8511049777I0410080000299817000000192333927156Kaufman
D8511049777I0410080000299818000000059003924884Martin

my spec sheet:

D: starting position at 1, and field lengh is 1
8511049777: starting position at 2, and field lengh is 10
I: starting position at 12, and field lengh is 1
04/10/08: starting position at 13, and field lengh is 6
0000299817: starting position at 19, and field lengh is 10
000000192333: starting position at 29, and field lengh is 12
# 2  
Old 04-30-2008
Your posting history indicates that you should start to learn sed, awk and maybe shell.

hint: figure out what ${variable:n1:n2} does in bash
# 3  
Old 05-01-2008
i used sed to get rid of / , . and space. how do i insert zero(0) to make my field lengh = 10 and other field lengh = 12
# 4  
Old 05-01-2008
It's not clear what is the record format of your input file. Are all your records fields separated by a space or are all fixed in length?

Using sed to get rid of useless characters will be ok only in the second case, otherwise how could you then distinguish one field with the other if they aren't fixed in length?
"1,923.33" looks like an amount of money, which I will doubt it will be the same length for all the records!

If your input file is mixed up with both kind of records will be a lot harder or maybe impossible to parse and format the information you need.
# 5  
Old 05-01-2008
after i used sed to get my file looks like this:
D8511049777 I 041008 99817 192333 927156 Kaufman

cat filename | awk '{print $5}' > filename2

and then i used command below to add my 0.

sed -e :a -e 's/^.\{1,10\}$/ &/;ta'
sed '1,$s/ /\0/g; s/\-\-/\-/g'

wow! this site is very very helpful.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Downloading hdfs file to local UNIX through UNIX script

Hi All , I am very new to unix script.I am aware of unix commands but never put together in unix script level.If any one can suggest me technical guidance in the below scenario that will highly beneficial. Data have been already migrated from mainframe to Hadoop file system(HDFS).HDFS server... (15 Replies)
Discussion started by: STCET22
15 Replies

2. Shell Programming and Scripting

Check time stamp formate in file

I have to check whether last line of the file has time stamp or not. File.txt cong = 0 This formats a date and time into the given strftime() format = 09 Dates can be passed to Smarty as unix timestamps = 56789 mysql timestamps or any string made up =98 Since Smarty-2.6.10 numeric... (4 Replies)
Discussion started by: Roozo
4 Replies

3. Shell Programming and Scripting

File Transfer from Window server to UNIX and UNIX to UNIX

Dear All, Can someone help to command or program to transfer the file from windows to Unix server and from one unix server to another Unix server in secure way. I would request no samba client. (4 Replies)
Discussion started by: yadavricky
4 Replies

4. UNIX Desktop Questions & Answers

Can Unix access Windows' File through Command Prompt in Unix

Hi all, I wish to know whether Unix can access window's file in Unix's terminal? Apart from that, how to copy files or share files between Window and Unix? I get to know of secure copy, however, my company's Unix does not support the feature of secure copy? Any other method for me to share/... (5 Replies)
Discussion started by: jessy83
5 Replies

5. Shell Programming and Scripting

UNIX script to FTP file from UNIX server to windows

Hi, I am new to this subject.....Can someone please help me out with the script... unix usernm "sdhftst" unix pwd "chsd13" windows usernm "dfghtst" windows pwd "chsd13" path..../xxx/xxxxx/xxxxxx/xxxxxxx please can u get me a script...its only one file to get ftp. Thanks... (2 Replies)
Discussion started by: himakiran9
2 Replies

6. Shell Programming and Scripting

Batch job in unix server to move the pdf file from unix to windows.

Hi Experts, I have a requirement where i need to setup a batch job which runs everymonth and move the pdf files from unix server to windows servers. Could some body provide the inputs for this. and also please provide the inputs on how to map the network dirve in the unix like that... (1 Reply)
Discussion started by: ger199901
1 Replies

7. Shell Programming and Scripting

Need to write a script to reformat a file in unix but not familiar with unix

unix script must do the fiollowing open a file containing comma delimited records > each record contains 10 fields > removes the 2nd field and use that same field containing fields 2 to 10 the original record after fprocessing should containing fields 1 and 3 a new erecord must be... (10 Replies)
Discussion started by: dwightja
10 Replies

8. Shell Programming and Scripting

Can we call JSP file from Unix.if so how.Please help me.Im newbie to Unix

Hi Can we call a jsp page from Unix.if so please let me know how we can.. thanks for the help in advance... thanks kumar (0 Replies)
Discussion started by: mailsukumar
0 Replies

9. Shell Programming and Scripting

How to solve formate peroblem

I have converted an excel file in unix accessible form using Spreadsheet::ParseExcel. It coverting perfectly but the problem is while coverting there is one column in the excel sheet which is when coverted in unix it shows the value along with some extra value like : in excel sheet the value in... (0 Replies)
Discussion started by: akash
0 Replies

10. Shell Programming and Scripting

FTP script for sending a file from one unix directory to another unix server director

Hi, My local server is :/usr/abcd/ Remote server is :/Usr/host/test/ I want to send files from local unix directory(All files starting with O_999) to remote host unix directory. Can any body give me the Unix Shell script to do this. One more doubt: Shall we need to change the file... (1 Reply)
Discussion started by: raja_1234
1 Replies
Login or Register to Ask a Question