Formatting fields of a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Formatting fields of a file
# 1  
Old 08-10-2005
Bug Formatting fields of a file

I have a file with n number of cols. I need to modify the size of each field. it may be either increase or decrease the present size of the field.

can anybody help me in this plz


thanks in advance
# 2  
Old 08-10-2005
U may try something like :
1) Awk '{printf (substr($0,m,n)" "substr($0,x,y)\n) }' <file> to select the fields as ur need.
2) or awk '{printf "%s\t%d"\n,$1,$2) <file>
# 3  
Old 08-11-2005
Try...
Code:
 awk ' {
    for(x=1; x<=NF; x++) {
        a[NR, x] = $x
        if (length($x) > ma[x])
            ma[x] = length($x)
    }
    if (NF > cm)
        cm = NF
 }
 END {
    for (y=1; y<=NR; y++)
       for (x=1; x<=cm; x++)
          printf ("%" ($x~/[A-Za-z]/?"-":"") ma[x] "s" (x==cm?ORS:OFS)), a[y,x]
 }' file1 > file2

# 4  
Old 08-11-2005
thanks for the code. Can u plz explain me the code?
# 5  
Old 08-11-2005
Which part don't you understand?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Formatting data in a raw file by using another mapping file

Hi All, i have a requirement where i need to format the input RAW file ( which is CSV) by using another mapping file(also CSV file). basically i am getting feed file with dynamic headers by using mapping file (in that target field is mapped with source filed) i have to convert the raw file into... (6 Replies)
Discussion started by: ravi4informatic
6 Replies

2. Shell Programming and Scripting

Formatting file data to another file (control character related)

I have to write a program to read data from files and then format into another file. However, I face a strange problem related to control character that I can't understand and solve. The source file is compose of many lines with such format: T_NAME|P_NAME|P_CODE|DOCUMENT_PATH|REG_DATE ... (3 Replies)
Discussion started by: hk6279
3 Replies

3. Shell Programming and Scripting

Need help in formatting a file.

Hi, I have a file in the following format. cat input name: abcd_ef_1 234:343:343 343:234:343 name : abcdef_2 2343:2343:3434: w3243:wr43:2343 2343:2343:23343:3432 2343:34234:2343 name: 3432_343_3 23432:2343 2343:23432:32432 23432:23432:3432432 As you can see... (2 Replies)
Discussion started by: jpkumar10
2 Replies

4. Shell Programming and Scripting

File formatting

Hi, I have a file which contains data in this format # User@Host: abc @ Id: 0000000 # Query_time: 0.000070 Lock_time: 0.000000 Rows_sent: 1 Rows_examined: 0 SET timestamp=00000000; SELECT @@version, @@version_comment; # User@Host: abcd @ Id: 00000000 # Query_time: 0.000228 ... (6 Replies)
Discussion started by: arijitsaha
6 Replies

5. Shell Programming and Scripting

File formatting

I need to count the number of lines between two sets of pattern in a file and delete those lines from that file e.g From jyotiv@yahoo.com test test2 test3 test4 test5 test6 From Jyotiv@yahoo.com So count lines from test to test6 and delete it from the start of file till next From... (1 Reply)
Discussion started by: jyotiv
1 Replies

6. Shell Programming and Scripting

Formatting and combining fields of the input file

Hi, I have a file of the following format: AV 103 AV 104 AV 105 AV 308 AV 517 BN 210 BN 211 BN 212 BN 218 and the desired output is : AV 103-105 3 AV 308 1 AV 517 1 BN 210-212 3 (5 Replies)
Discussion started by: rochitsharma
5 Replies

7. UNIX for Dummies Questions & Answers

Formatting Multiple fields on 1 line to multiple rows

I'm trying extract a number of filename fields from a log file and copy them out as separate rows in a text file so i can load them into a table. I'm able to get the filenames but the all appear on one line. I tried using the cut command with the -d (delimiter) option but cant seem to make it... (1 Reply)
Discussion started by: Sinbad-66
1 Replies

8. Shell Programming and Scripting

help with file formatting

Hi, I have a file with below contents: AAA pqr,jkl,mnop,abcd BBB abc,pqrs,xyz,uvw, efgh,uvw, rpk CCC 123,456,789 Need output file as below: AAA,pqr,jkl,mnop,abcd BBB,abc,pqrs,xyz,uvw,efgh,uvw,rpk (18 Replies)
Discussion started by: prvnrk
18 Replies

9. Shell Programming and Scripting

formatting the fields

hi i am using the following code in my shell script awk -F":" '{printf("%-20.20s:%-20.20s:%-20.20s:%-20.20s:%-15.15s:%-3.3s:%-19.19s:%-2.2s:%-20.20s:%-15.15s:%-2.2s\n", $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11)}' $DIALPBIN/temp1.txt > ${DIALPBIN}/temp2.txt actually the 5th field should not... (17 Replies)
Discussion started by: priyanka3006
17 Replies

10. Shell Programming and Scripting

file formatting ?

I have a log file with start and finish times for various scripts. The start and finish times just get appended one after the other. I want the start and finish times to be on the same line seperated by a comma. Below is an example of the log file I want formatted. logfile: 23:17:15 23:20:26... (16 Replies)
Discussion started by: cstovall
16 Replies
Login or Register to Ask a Question