Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I had no idea how to word the title.

I need to take an output such as:

[~]# cat file

and turn it into an output such as:


Any assistance here would be greatly appreciated.

share|improve this question
This will probably get moved over to Stack Overflow, and then closed as a duplicate of…. I had to strongly resist the urge to simply copy and paste the accepted answer over there to this thread, just for the potential rep points, but that would be cheating, IMHO. – Jed Daniels Jun 21 '10 at 20:38
Yeah, I would have answered using sed, too. – Dennis Williamson Jun 21 '10 at 20:45
up vote 9 down vote accepted

while read user
        read domain
        echo $user $domain     


cat file | scriptname
share|improve this answer
+1 -- Very nice! – Christopher Karel Jun 21 '10 at 20:30

I figured this out with some array-age

for i in `seq 1 2 ${#array[@]}` ; do echo "${array[$i]} ${array[$i + 1]}"; done
share|improve this answer

Man, there's gotta be an easy way to do this. I clearly haven't got enough sleep, because I can't think of any. But, because I don't like arrays, I used a for loop. It essentially goes through each LINE, and outputs the even numbers to a new file without a linebreak, and appends the odd ones with a break. Seems to work!

for LINE in $(cat file.txt);do
  if [ $(($COUNT % 2)) -eq 0 ];then 
      echo -n $LINE >> newfile.txt
      echo -n " " >> newfile.txt
      echo $LINE >> newfile.txt
COUNT=$((COUNT + 1))

--Christopher Karel

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.