Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

appending line with characters

Status
Not open for further replies.

arunrr

Programmer
Oct 2, 2009
103
0
0
US
Hello,

I have the following input file...

1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30

Basically it is a monthly calendar (June 2011). I need to fill the blanks with 'X', meaning...

X X X 1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 X X

I top row is straight forward, as the following does it...

sed 's/ / X /g'

Please help with the bottom row.

Thanks
Arun
 
Hi,

This is done. Used the following...

cat input | sed '/^$/d' | awk '{if (NF<7) for(i=NF;i<7;i++) $0=$0" X"; printf $0"\n"}'

Thanks
AR
 
Hi

Well, it can be solved with [tt]sed[/tt] alone :
Code:
sed 's/   / X /g;:b;/.\{20\}/!{s/$/  X/;bb}' input

[gray]# or[/gray]

sed 's/   / X /g;:b;s/^.\{,19\}$/&  X/;tb' input
But I still have the feeling of walking the wrong way.



Feherke.
 
If this is for a web page you may be better of performing the whole task on the web server (perhaps with a PHP script)

I think further information is required before the best solution can be advised.


I do not Have A.D.D. im just easily, Hey look a Squirrel!
 
Hi

I agree.

I would add that a database would be a better storage for the calendar data. Searching and statistical queries would be easier to add later. Also web based calendars usually have different overview levels : year, month, week. Those would be also easier to achieve with PHP and SQL.


Feherke.
 
Feherke, IPGuru,

Thanks for the all the advice. Will apply...

Arun
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top