Help with formatting file in C shell!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with formatting file in C shell!
# 1  
Old 05-28-2013
Help with formatting file in C shell!

Hi Guys,
I have written a matlab script that does, thresholding of the data and creates a single column of data which i save as a text file in my home directory. Now would like to format that text file so that I all the numbers are 4 digits, if not than add 000 in front of the number if number is 1 digit or 00 if the number is 2 digit.
Code:
input.txt
1
22
300
4000
output.txt
0001
0022
0300
4000

Thank you so much in advance. I would prefer the solution in c shell!
# 2  
Old 05-28-2013
Use printf "%04d" with the value from the file.
This User Gave Thanks to Scott For This Post:
# 3  
Old 05-28-2013
Code:
awk '{printf("%04d\n", $0)}' input.txt

This User Gave Thanks to shamrock For This Post:
# 4  
Old 05-29-2013
Thank you all for you help.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Formatting in a table via shell

Hi I have the below output: 736f14c4-eda2-4531-9d40-9de4d6d1fb0f An account already exists for this email address. Please enter a different email address. c3716baf-9bf8-42da-8a44-a13fff68d20f An account already exists for this email address. Please enter a different email address. Is... (4 Replies)
Discussion started by: ankur328
4 Replies

2. Shell Programming and Scripting

Formatting a file using shell script

Hi, Please find the below lines of a file B1/OT "GIB10" 837 130308 1351 MONORONOUS DIGI PATH FAULT SUPER B1/OT "GIB10" 520 130418 1537 MONORONOUS DIGI PATH FAULT SUPER B1/XT "GIB10" 762 130421 0653 TV Y-CEIVER ADMIN RXOCF-62 241_OKEBOLE_NEW 1 B1/XT "GIB10" 385 130425 1931 TV Y-CEIVER... (2 Replies)
Discussion started by: Ardhendu
2 Replies

3. Shell Programming and Scripting

Formatting File Using Shell Script

Hi Team, We have a requirement where we need to format input file using shell script by meeting the below conditions. 1. 1. Ignore first 549 characters of that file. 2. 2. After that we need to make a file of 100 characters per line, repeat it until the 3rd ... (16 Replies)
Discussion started by: ataneja7
16 Replies

4. Shell Programming and Scripting

AWK/Shell script for formatting data in a file

Hi All, Need an urgent help to convert a unix file in to a particular format: **source file:** 1111111 2d2f2h2 3dfgsd3 ........... 1111111 <-- repeats in every nth line. remaining all lines will be different 123ss41 432ff45 ........... 1111111 <-- repetition qwe1234 123weq3... (1 Reply)
Discussion started by: rajivnairfis
1 Replies

5. Shell Programming and Scripting

formatting a shell script

there is one shell which calls for different sql scripts. output of different are formatted in frame like structure.i want columnar wise formatting to be done in such a manner that output of one sql may be comon input of rest sqls . ERC DML Closure Date ER DML SAP Transfer Date ... (0 Replies)
Discussion started by: arc
0 Replies

6. Shell Programming and Scripting

Shell Script Problems, Lose formatting when copy pasting from formatted file.

Hello, I'm having trouble with formatting some text via the terminal. I can get it perfectly formatted, but when I try and copy paste the text from the output file it loses it's formatting. Very frustrating! Basically I have 7 files (data data2 data3 data4 data5 data6 data7) containing a... (13 Replies)
Discussion started by: facetoe
13 Replies

7. Shell Programming and Scripting

Formatting a file using shell script

I have a file with contents something similar to as below : SVCNAME,12m-1a,1a-2a,2a-3a,3a-4a,5a-6a,6a-7a,7a-8a,8a-9a,9a-10a,10a-11a,11a-12n,12n-1p,13p-14p,14p-15p,15p-16p,16p-17p,17p-18p,18p-19p,19p-20p,20p-21p,21p-22p,22p-23p,11p-12m, TOTALS... (5 Replies)
Discussion started by: deo_kaustubh
5 Replies

8. Shell Programming and Scripting

Formatting the text file using shell script

How to add the filename to end of each line with | as seperator, except first and last line of the file(s) in directories(with diff tree structure) using shell script?. And also how to replace a list of strings with another set of strings, which is present in a file?. Kindly help out on... (1 Reply)
Discussion started by: av_vinay
1 Replies

9. Shell Programming and Scripting

[SHELL] Output formatting

I am looking for a way to format the output of this string into comma separated values (.csv) so I can import into excel. Also I want to remove any white space generated by the commands, particularly the dmidecode as the output has lots of space in front of Serial Number. #!/bin/bash for... (8 Replies)
Discussion started by: Adrnalnrsh
8 Replies

10. Shell Programming and Scripting

formatting a file using shell script

Hi I have to do the following.I have to format a file test.t The contents are # Header 1231 xyz asdf asdapsdcsd //string1 = "pqrs" //string1 = "abcd"; //info //string1 = "*pqrs"; //add string1 = "#123"; //sub //string1 = "#1234567890" data = check(string1) //string1 = "#1234567890"... (12 Replies)
Discussion started by: gopsman
12 Replies
Login or Register to Ask a Question