Format each line of the file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Format each line of the file
# 1  
Old 12-18-2008
Format each line of the file

I have a file -> testfile

title title title title
---- ---- ---- ----
vimal thoma 100 approved
vimal yes 2 allowed

I want to change this file as

title ,title ,title ,title
---- ,---- ,---- ,----
vimal ,thoma ,100 , approved
vimal ,yes ,2 ,allowed

How can i do this??
# 2  
Old 12-18-2008
Sorry i want the file in the following format

title ,title ,title ,title
---- ,---- ,---- ,----
vimal ,thoma ,100 , approved
vimal ,yes ,2 ,allowed
# 3  
Old 12-18-2008
I am not able to display it here... each line comes with the following format

title<10 spaces>title<5spaces>title<5spaces>title

I want the line as

itle<10 spaces><comma>title<5spaces><comma>title<5spaces><comma>title
# 4  
Old 12-18-2008
nawk -f vj.awk myFile

vj.awk:
Code:
BEGIN {
  OFS=","
  fn=split("15 10 10 10", fA)
}
{
   for(i=1;i<=NF; i++)
      printf("%-*s%c", fA[i], $i, (i==NF) ? RS : OFS)
}

Adjust the values in the 'split' statement as needed.
Good luck.
# 5  
Old 12-18-2008
Sir,

Wonderfull
it really workswell
but can you please look the data below?

Code:
DCR/MR          RELATED WORK REQUEST      DATE OPENED     PROCESSED BY
------          --------------------      -----------     ------------
 
MR-49347        type1                     12-01-2008      aj842q          Please build the package 3-cbsJDBCSPools pack
MR-49347        type1                     12-01-2008      mpdwwrz         Please build the package 3-cbsJDBCSPools pack
MR-49348        WR257                     12-01-2008      mpdwwrz         Please execute the implementation plan.      
MR-49351        WR-370<NL>RCCB:3938       12-01-2008      aj842q          Please install in sys and perf boxes as per t
MR-49351        WR-370<NL>RCCB:3938       12-01-2008      mpdwwrz         Please install in sys and perf boxes as per t
MR-49354        Carbon 3.2                12-01-2008      vj8436          Creation of New Harvest Environment          
MR-49354        Carbon 3.2                12-01-2008      yhbldrr         Creation of New Harvest Environment


Last edited by radoulov; 12-18-2008 at 10:10 AM.. Reason: added code tags
# 6  
Old 12-18-2008
Here i want the comma in,

DCR/MR, RELATED WORK REQUEST, DATE OPENED, PROCESSED BY

and the same order has to follow down also
# 7  
Old 12-18-2008
Cannot do - there's no way to determine the start and the end of the field AND most of the field values have embedded spaces (with 'space' being a field separator as well).

If you manage to get a file where the field names (header) and the field values are, say, quoted - it might be possible to do. Something along these lines:
Code:
"MR-49354" "Carbon 3.2" "12-01-2008" "vj8436 Creation of New Harvest" Environment

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Multi line log files to single line format

I want to read the log file which was generate from other command . And the output was having multi line in log files for job name and server name. But i need to make all the logs on one line Source file 07/15/2018 17:02:00 TRANSLOG_1700 Server0005_SQL ... (2 Replies)
Discussion started by: ranjancom2000
2 Replies

2. Shell Programming and Scripting

Need help to format one txt file to required format

Hello Everyone, I have one source file which is genarated by SAP in different format(Which I've never seen). I need to convert that file to required format and I need to read this target file from Datastage to use this in my Jobs. So I do not have any other options except to use Unix script to... (4 Replies)
Discussion started by: Prathyu
4 Replies

3. UNIX for Dummies Questions & Answers

How to print the line from the file in the desired format:?

I am reading a file of Linux ( like mentioned below) & the data is represented in a single line like mentioned below: 11/03 4:00 39992 0.098 5.195 0.034 0.001 1.091 182 0.000 0 0.071 4.252 0.033 0.001 666.53 Now i want to print the result in other file something like this :- 39992... (5 Replies)
Discussion started by: Anamica
5 Replies

4. Shell Programming and Scripting

Extract Line and Column from CSV Line in ksh or bash format

Hi, I was doing some research and can't seem to find anything. I'm trying to automate a process by creating a script to read a csv line and column and assigning that value to a variable for the script to process it. Also if you could tell me the line and column if it's on another work ... (3 Replies)
Discussion started by: vpundit
3 Replies

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

6. Shell Programming and Scripting

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.... (2 Replies)
Discussion started by: Samtel
2 Replies

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

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

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

10. 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
Login or Register to Ask a Question