Adjust format file


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Adjust format file
# 1  
Old 03-07-2006
Adjust format file

Hi all...

i have a question, and i don`t know what to do ... i have a flat file what is separated by ";" and i need format it... here is an example:

this is what i have:

AAA ; BBB ; 1 ; 1.1 ; 1.2 ; 1.3 ; 2 ; 2.1 ; 2.2 ; 2.3 ; 3 ; 3.1 ; 3.2 ; 3.3 ; .......
.........

there are a lot of columns and lines (records), and i need this output:

AAA ; BBB; 1 ; 1.1 ; 1.2 ; 1.3
AAA ; BBB; 2 ; 2.1 ; 2.2 ; 2.3
AAA ; BBB; 3 ; 3.1 ; 3.2 ; 3.3
..........

is that possible?
any idea, thanks..
# 2  
Old 03-07-2006
Hi,
This is not very clean, but will work if there are always six fields per line in the output.

Quote:
cat f1.txt | awk -F ';' '{
for (i=3;i<NF;i++)
{
j=i+1
k=i+2
l=i+3
printf("%s;%s;%s;%s;%s;%s",$1,$2,$i,$j,$k,$l)
print ""
i=i+3
}
}'
if you can have something different post back

Gaurav
# 3  
Old 03-07-2006
it doesn't works

i run it and i have the next error message:

code:

cat f1.txt | awk -F ';' '{
for (i=3;i<NF;i++)
{
j=i+1
k=i+2
l=i+3
printf("%s;%s;%s;%s;%s;%s",$1,$2,$i,$j,$k,$l)
print ""
i=i+3
}
}'

message error:

awk: syntax error near line 1
awk: bailing out near line 1

why? who can explain it please...
any idea, thanks
# 4  
Old 03-07-2006
nawk -f deb.awk myFile.txt

deb.awk:
Code:
BEGIN {
  div=4
  FS=OFS=";"
}
{
  for(i=3; i <= NF; i+=div)
    print $1, $2, $i, $(i+1), $(i+2), $(i+3)
}

# 5  
Old 03-08-2006
Quote:
Originally Posted by DebianJ
i run it and i have the next error message:


message error:

awk: syntax error near line 1
awk: bailing out near line 1

why? who can explain it please...
any idea, thanks
Hi ,
Its working fine for me

Gaurav
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 seperate text and adjust format like this?

in example.txt file is below ADD PDU:SRN=0,PDUID=LOCAL,NAME="PDU_0",PSV=LOW,MOG="PUBLIC",REFERABLE=YES; ADD PDU:SRN=2,PDUID=LOCAL,NAME="PDU_1",PSV=LOW,MOG="PUBLIC",REFERABLE=YES; ADD MODULE:MID=84,MT=DSU,SRN1=0,SN1=4,MNAME="DSU84"; ADD MODULE:MID=85,MT=DSU,SRN1=0,SN1=4,MNAME="DSU85"; How to... (2 Replies)
Discussion started by: swensens
2 Replies

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

3. UNIX for Dummies Questions & Answers

Convert UNIX file format to PC format

Hi All, Is there any way to convert a file which is in UNIX format to a PC format.... Flip command can be used , apart form this command can we have any other way.... like usinf "awk" etc ..... main purpose of not using flip is that my Kshell doesnot support this comamnd.... (1 Reply)
Discussion started by: Samtel
1 Replies

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

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

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

7. Shell Programming and Scripting

How to adjust spacing

Is there a way to adjust spacing of a line using k shell? e.g I have a file below $ cat file1 AAA BBB CCC A B C AAAA BB CC I want each word to be adjusted with spaces to have 10 character length like below: AAA BBB CCC A B C AAAA BB CC Any... (4 Replies)
Discussion started by: stevefox
4 Replies

8. UNIX for Advanced & Expert Users

adjust files

hi... i have a big problem, and i don't know how to solve it. here is the thing: i have 12 files, which are flat files, with several records(lines), and each record has 3 fields, wich are separated by pipe (|), something like this: file 1: 33|12|2000 33|22|3000 66|24|3000 99|48|4000... (7 Replies)
Discussion started by: DebianJ
7 Replies

9. Shell Programming and Scripting

Adjust the db script

Enclosing a script that is used everyday for database shutdown. In here you will find some code that checks oracle version. That part is very unnecessary since we use only 8.1.7 and will never go back.. Can anyone help me by modifying the code, to never use that part and readjust so script does... (1 Reply)
Discussion started by: ST2000
1 Replies

10. Filesystems, Disks and Memory

Cannot adjust division

I have a doubt with an error message, and i want to be sure if this is a normal situation or not. Situation: I was formating and installing a SCSI 36Gb HD with UNIX SCO 5.05, the problem happens when is making the division and filesystem on disk 1, and the message error is "Exit value 139... (1 Reply)
Discussion started by: jav_v
1 Replies
Login or Register to Ask a Question