Padding space with each column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Padding space with each column
# 1  
Old 09-27-2012
Padding space with each column

Hi

How do I a add space with each column .

Each column has fixed size
like 1 st column = 10
2nd column = 20

In each column data can be of variable length.So rest of the length should be space

Frank Student
Sue Admin
# 2  
Old 09-27-2012
Code:
perl -alne '{$col1=" "x10;$col2=" "x20;print $F[0].$col1.$F[1].$col2}' input_file

# 3  
Old 09-27-2012
Code:
while read col1 col2 rest; do printf "%-10s%-20s\t%s\n" $col1 $col2 $rest; done < file

# 4  
Old 09-27-2012
My Code is Like this.

where I am reading a txt file line by line,processing the file by calling procedure
and writing the ouput in txt file.

How do i write the code to to make sure that each coolumn
f1 output and f3 are always of fixed length
fi = 58
Output = 18
f3 = 233

Code:
#!/bin/ksh
  
 #File name of the input file
FILE=${P1}  BAKIFS=$IFS
 IFS=$'\n'
 exec 0<"$FILE"
 echo "File to be processed.....: ${FILE}"  
 while read -r line
 do
  f1=`echo "$line" |cut -b 1-58 `
 f3=`echo "$line" |cut -b 77-400`
 v_curre=`echo "$line" |cut -b 59-76`
 OUTPUT=`sqlplus -s ${LOGIN} <<EOF
 set pages 0 lines 120 trimout on trimspool on tab off echo off verify off feed off serverout on
 var mavar varchar2(100);
 select xxc_test.emp_first_name('${v_curre}')  
 into :mavar from dual;
 print mavar;
 exit;
 EOF`
 #echo "v_curre:" "$v_curre"
  
 while read f1 OUTPUT f3;
 do 
  printf "%-10s%-20s\t%s\n" $f1$OUTPUT$f3 ;
 done >> $NEW_FILE_NAME
 done
 IFS=$BAKIFS

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Create the space only in the Third column by awk

Hi All , I am having an input file like this Input file r s e y Pin Numbers s n eppppppppppppppppppc ... (3 Replies)
Discussion started by: kshitij
3 Replies

2. Shell Programming and Scripting

Insert space in specific column among many columns

Hello, I have some problem in inserting the space for the pairs of columns. I have the input file : I used this code below in replacing it using space in specific column (replace space in each two columns) sed -e "s/,/ /2" -e "s/,/ /3" inputfile Output showed : However, I have many... (3 Replies)
Discussion started by: awil
3 Replies

3. Shell Programming and Scripting

Sort, sed, and zero padding date column csv bash scripting

Hello people, I am having problem to sort, sed and zero padding of column in csv file. 7th column only. Input of csv file: 1,2,3,4,5,6,4/1/2010 12:00 AM,8 1,2,3,4,5,6,3/11/2010 9:39 AM,8 1,2,3,4,5,6,5/12/2011 3:43 PM,8 1,2,3,4,5,6,12/20/2009 7:23 PM,8 Output:... (5 Replies)
Discussion started by: sean1357
5 Replies

4. Shell Programming and Scripting

Delete Space between last and first column

HI Input A R04 tion=1 Li 51599 R08 tiea=1 Li 51995 R11 ocatea=1 Li 51992 R12 nArea=1 Li ... (2 Replies)
Discussion started by: asavaliya
2 Replies

5. Shell Programming and Scripting

awk padding column

Hello, i am trying to pad a column A1 A2 A10 B2 B8 B12 to look like A01 A02 A10 B02 B08 B12 using awk (6 Replies)
Discussion started by: mykey242
6 Replies

6. UNIX for Dummies Questions & Answers

Padding With White Space Between Variables

Dear Users, How do we pad with white space of particular length between two variables. For Example: Suppose i define the variables as follows: a='toyota' b='camry' c='honda' d='accord' e=`echo "$a"'\n'"$b"` f=`echo "$c"'\n'"$d"` If i do an echo on variables e and f i get :... (1 Reply)
Discussion started by: sandeep_1105
1 Replies

7. AIX

column space

Is it possible to give spaces using unix commands at a particular column? eg: 123 56 89(input) 123 56 89(output) (4 Replies)
Discussion started by: rollthecoin
4 Replies

8. UNIX for Dummies Questions & Answers

Quick help on space padding

Hi all, I need to create a header record of width 121 charecter with below fields, position 001-001 - 0 position 002-15 - filled with space position 016-020 - date value position 021-121 - filled with space Iam using the below code: echo 0"14 spaces"$date"100 spaces" >> output.txt ... (3 Replies)
Discussion started by: Lokesha
3 Replies

9. Shell Programming and Scripting

Help with script printing column with space

I am having some issues with a script taking in column #5 which has a space and splitting it into another line. I don't want this but I can not figure out why its doing this. Any help is appreciated. Here is my input file (comma delimited): ... (4 Replies)
Discussion started by: n3al10
4 Replies

10. UNIX for Dummies Questions & Answers

text formating/Text space padding

Hi, How do I format the following? I have a for loop that retrieves me the path and file name of a file. In column fashion I would like to add the time and another variable containing the file's size. This will result in all the time being under each other and all the file size's being under... (6 Replies)
Discussion started by: hugow
6 Replies
Login or Register to Ask a Question