LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   bash printf anyone? (https://www.linuxquestions.org/questions/programming-9/bash-printf-anyone-59565/)

gumby 05-13-2003 09:45 AM

bash printf anyone?
 
How would one format this string in printf?

"day2.20030308.d"

DIR=day2.20030308.d

I have been using:

awk '{printf '`echo $DIR`' "|%-17s|\n", $1}' reg <filename>

And get a parse error on the dot before the d . Does printf look at this as a regular string?

vladkrack 05-13-2003 10:00 AM

Try:

echo $DIR | awk '{printf "|%-17s|\n", $1}'

Is that exit that you want?

gumby 05-13-2003 11:26 AM

No.

I am trying to get the DIR variable to repeat in the left-hand column like so:

awk '{printf '`echo $DIR`' "|%-15s|\n", $1}' reg
0.200303|Maria |
0.200303|Christina |
0.200303|Nancy |
0.200303|Juan |
0.200303|Lourdes |
0.200303|Carlos |
0.200303|Mario |
0.200303|Malia |
0.200303|Eloisa |
0.200303|Josie |

DIR should contain "day2.20030303" not 0.20030303

vladkrack 05-13-2003 11:44 AM

Then could be used:

DIR=2.200303

awk '{printf '$DIR' "|%-15s|\n", $1}' arq
2.2003|Maria |
2.2003|Christina |
2.2003|Nancy |
2.2003|Juan |
2.2003|Lourdes |
2.2003|Carlos |
2.2003|Mario |
2.2003|Malia |
2.2003|Eloisa |
2.2003|Josie |

I didn't understand if the $DIR is already what you have, but it can be modified if necessary ...

gumby 05-13-2003 11:51 AM

That's getting closer to what I want. Thanks!!


All times are GMT -5. The time now is 12:38 AM.