0

i just want to fetch lines from a csv file and print it line by line. the thing is the below code fetches the 4th column and prints it. What i want to do is, i just want to give 100 char spaces for that column printing. if that column has 10 chars i just wanna print that and rest 90 chars spaces should be empty in that line.

cat filename | awk -F"," '{print $4}'
RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93
Sharvaa
  • 41
  • 9

1 Answers1

3

AWK has printf() function that support format. With format "%100s" and "%-100s" you can pad printed string with spaces from left or right:

 $ echo "a\nb\nc\nd" | awk '{ printf("|%10s|\n", $1);}'                                  
 |         a|
 |         b|
 |         c|
 |         d|
 $ echo "a\nb\nc\nd" | awk '{ printf("|%-10s|\n", $1);}'                                    
 |a         |
 |b         |
 |c         |
 |d         |
 $
kofemann
  • 4,217
  • 1
  • 34
  • 39