Operating System - HP-UX
1834912 Members
2996 Online
110071 Solutions
New Discussion

Script Help - put output in columns?

 
SOLVED
Go to solution
Greg Stark_1
Frequent Advisor

Script Help - put output in columns?

I have a text file that looks like this:

UserA
DateA
UserB
DateB
UserC
DateC

I want to run a command against it to change it to this:

UserA DateA
UserB DateB
UserC DateC

Basically putting the data into 2 columns (one of user names, one of dates associated with each user name). Is this possible?

thanks again,
Greg
5 REPLIES 5
Michael Schulte zur Sur
Honored Contributor
Solution

Re: Script Help - put output in columns?

Hi,

sure, that's simple
awk '{l1=$0;getline;print l1" "$0;)}'

hth,

Michael
Greg Stark_1
Frequent Advisor

Re: Script Help - put output in columns?

Thanks, but I tried your suggestion and I got no output. It looks as tho there is only a close paren and not open. Is that correct?
Greg Stark_1
Frequent Advisor

Re: Script Help - put output in columns?

Sorry, worked afterall. I missed a space in the command.

Thanks,
Greg
Michael Schulte zur Sur
Honored Contributor

Re: Script Help - put output in columns?

Hi Greg,

actually it is me to say sorry because I forgot to add the filename as parameter after the awk command.

thanks for the points,

Michael
Mike Stroyan
Honored Contributor

Re: Script Help - put output in columns?

I think that learning to do the task with awk (or perl) will serve you better for future tasks because scripting languages are so flexible.

On the other hand, you can get the effect you want with simple options to the pr command.
pr -2tas' ' yourfile