format values in a text file using cat command

Hello...

Is it possible that we can change the format of the values we entered in a text file using cat?

Like for example, I will create a text file names.txt using cat and as I save the names and view the text file... the format will be like this

but here in my code....

echo "Enter First Name: "
read firstname
echo $firstname | cat >> names.txt

echo "Enter Last Name: "
read lastname
echo $lastname | cat >> names.txt

It would make this output in the notepad...

I hope someone can help me regarding this....

Thank you so much :slight_smile:

Prize for the most pointless use of cat is winging its way to you :wink:

echo -e "$firstname\t" >>names.txt
...
echo -e "$lastname\n" >>names.txt
  1. You don't need "cat" command:
echo "$firstname " >> names.txt
  1. Your cygwin commands output text in unix format - with just '\n' char at the end of lines, but notepad wants text in dos format - with '\r\n". You can install 'notepad++', it understands unix format. Or you can convert the text with a lot of ways - see How do I convert between Unix and Windows text files? - Knowledge Base.

Thanks for that :slight_smile:
nyaa... I'm just a newbie here.. XD

anyway... I tried the code you've suggested but it gives me this kind of output in the notepad

I want to have an output similar to this photo below

I really appreciate that you've replied on my thread ^^ God bless you :))

---------- Post updated at 03:08 AM ---------- Previous update was at 02:27 AM ----------

I tried notepad++

with the following codes

echo "Enter First Name: "
read firstname
echo -e "$firstname\t" >> names.txt

echo "Enter Last Name: "
read lastname
echo -e "$lastname\n" >> names.txt

but then it gives me this output in the notepad++

I want that the output in the notepad++ will be like the picture below

How can that be possible?

Hoping for your help guys .... Thank you so much :slight_smile:

You can use

echo "Enter First Name: "
read firstname
echo -ne "$firstname\t" >> names.txt

echo "Enter Last Name: "
read lastname
echo  "$lastname" >> names.txt

Or (better):

echo "Enter First Name: "
read firstname
printf "$firstname\t" >> names.txt

echo "Enter Last Name: "
read lastname
echo "$lastname" >> names.txt

weeeee!!!!! Thank you sooo much Yuzu ... It really worked well :smiley:
That gave me the desired output I wanted .. :smiley:
Thank you soo much for helping me with this ^^
God bless you :))