format a flat file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting format a flat file
# 1  
Old 06-19-2009
format a flat file

i have a flat file with around 700 columns . i want to break it into a flat file with say five columns like

col1,col2,col3,col4
col5,col6,col7,col8
col9...... ,col700

how can i do this
# 2  
Old 06-19-2009
use a while read loop with IFS=","
# 3  
Old 06-19-2009
Code:
awk -F"," '{ for(i=1;i<=NF;i=i+5){    print $i,$(i+1),$(i+2),$(i+3),$(i+4)  } }' file

# 4  
Old 06-19-2009
working with large no of columns

I have a big file around 91 columns

when im running
awk -F"," '{ for(i=1;i<=NF;i=i+90){ print $i,",",$(i+1),",",.....$(i+90),$(i+91)} }'
bs > final

its giving me too many fields ....

---------- Post updated at 06:14 AM ---------- Previous update was at 06:11 AM ----------

bash-3.00$ awk '{print NF}' IRFEReconciliationReport-SPDM-AXJ_20090618_2.CSV
awk: record `Tracker ID#,RM Syste...' has too many fields

---------- Post updated at 06:38 AM ---------- Previous update was at 06:14 AM ----------

can we check for the 91st comma in the text line and insert a line feed ...

that should satisfy the need of the hour ..
1,2,3,4,..... ,90,91
92,93
# 5  
Old 06-19-2009
try with this

can you please try with this :

awk -F"," '{ for(i=1;i<=NF;i=i+90) { for(j=0;j<90;j++) { printf "%s," , $(i+j) } printf "\n" } }'
# 6  
Old 06-20-2009
Its giving the same error

awk: record `SPN 3, Revenue Clien...' has too many fields
record number 1
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to change the format of the date column in a flat file?

Hi, i have a flat file namely temp.txt with this data below ID|name|contact_date 101|Kay|2013-12-26 102|let|2013-12-26 I need to modify the date data in the flat file into MM/DD/YYYY HH24:MI:SS format let me know the code for this. Thank you! (5 Replies)
Discussion started by: srikanth_sagi
5 Replies

2. UNIX for Advanced & Expert Users

Converting the date format in a flat file

Hi All, I am new to this forum, could any one help me out in resolving the below issue. Input of the flat file contains several lines of text for example find below: 5022090,2,4,7154,88,,,,,4/1/2011 0:00,Z,L,2 5022090,3,1,6648,88,,,,,4/1/2011 0:00,Z,,1... (0 Replies)
Discussion started by: av_sagar
0 Replies

3. 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

4. Shell Programming and Scripting

Searching for Log / Bad file and Reading and writing to a flat file

Need to develop a unix shell script for the below requirement and I need your assistance: 1) search for file.log and file.bad file in a directory and read them 2) pull out "Load_Start_Time", "Data_File_Name", "Error_Type" from log file 4) concatinate each row from bad file as... (3 Replies)
Discussion started by: mlpathir
3 Replies

5. Programming

compare XML/flat file with UNIX file system structure

Before i start doing something, I wanted to know whether the approach to compare XML file with UNIX file system structure. I have a pre-configured file(contains a list of paths to executables) and i need to check against the UNIX directory structure. what are the various approches should i use ? I... (6 Replies)
Discussion started by: shafi2all
6 Replies

6. 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

7. UNIX for Dummies Questions & Answers

Convert UTF8 Format file to ANSI format

:confused: Hi i am trying to convert a file which is in UTF8 format to ANSI format i tried to use the function ICONV but it is throwing error Function i used it as $ iconv -f UTF8 -t ANSI filename Error iam getting is NOT Supported UTF8 to ANSI please some help me out on... (9 Replies)
Discussion started by: rajreddy
9 Replies

8. UNIX for Advanced & Expert Users

Convert UTF8 Format file to ANSI format

:) Hi i am trying to convert a file which is in UTF8 format to ANSI format i tried to use the function ICONV but it is throwing error Function i used it as $ iconv -f UTF8 -t ANSI filename Error iam getting is NOT Supported UTF8 to ANSI please some help me out on this.........Let me... (1 Reply)
Discussion started by: rajreddy
1 Replies

9. Shell Programming and Scripting

Help with a flat file!!!

Hi All, I get a flat file everyday with some records being invalid.Some records come with less number '|'.I just want to add the missing '|'s ,So the it doesnt give an error insufficient fields while loading...There area total of 32 pipes in each record. Input: ASADASD |Y|B|SDFGDSDFD| ... (3 Replies)
Discussion started by: kumarsaravana_s
3 Replies

10. UNIX for Advanced & Expert Users

Flat File Conversion Format

Hi all, I've a flat file in this format: = " Record 1 Field1 -> XXXX Field2 -> 9558 Field3 -> 55AA Record 2 Field1 -> YYYY Field2 -> 12345 Field3 -> aa23 " And i want to convert it to (4 Replies)
Discussion started by: Loobian
4 Replies
Login or Register to Ask a Question