General discussion

Locked

How do I redirect a tab to a file?

By iamsanchez ·
I'm trying to build a very simple script which take input from the user to build an address book. The response is then redirected to a simple file where the info will be stored in column format, separated by <TAB>, of course using the \t escape character, rith?

Except that I've tried everything and I have not been successful at getting the tab to separate my entries.

I tried to figure it out myself, but I've spent hours trying and nothing.

Any ideas out there?

Thank you
Rafael.
Here's my script...
-------------
#!/bin/sh

entry=y

while [ $entry = y ]
do
echo -n "Enter Name :";
read name
echo -n "Enter Street :";
read street
echo -n "Enter City :";
read city echo -n "Enter Province :";
read province
echo -n "Continue? (y)Yes (n)No ";
read entry

echo $name$street$cityt$province } >> adrbook
done

This conversation is currently closed to new comments.

7 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

How do I redirect a tab to a file?

by cpfeiffe In reply to How do I redirect a tab t ...

I haven't had much like getting tabs to work with echo in the past either, but try this awk command, its just as easy as the echo.

awk '{printf $name "\t" $street "\t" $city "\t" $province}' >> adrbook

You could replace your echo to adrbook line with that line and be in business or you could just insert five (or another number of spaces in your echo line like this

echo $name" "$street" "$city" "$province >> adrbook

But that isn't the same as using a real tab. Either waywill get you spacing between your variables.

Good luck.

Collapse -

How do I redirect a tab to a file?

by iamsanchez In reply to How do I redirect a tab t ...

Poster rated this answer

Collapse -

How do I redirect a tab to a file?

by ryttinch In reply to How do I redirect a tab t ...

Try the following:

#!/bin/sh

entry=y

while [ $entry = "y" ]
do
echo "Enter Name:"
read name
echo "Enter Street: "
read street
echo "Enter City: "
read city
echo "Enter Province: "
read province
echo "Continue? (y)es (n)o "
read entry

printf "%s\t%s\t%s\t%s\n" "$name $street $city $province" >> adrbook
done

It worked for me.

Chad

Collapse -

How do I redirect a tab to a file?

by iamsanchez In reply to How do I redirect a tab t ...

Poster rated this answer

Collapse -

How do I redirect a tab to a file?

by WANToolsMan In reply to How do I redirect a tab t ...

You could also try inserting the tab into double quotes, like this:

#!/bin/sh

entry=y

while [ $entry = y ]
do
echo -n "Enter Name :";
read name
echo -n "Enter Street :";
read street
echo -n "Enter City :";
read city
echo -n "Enter Province :";
read province
echo -n "Continue? (y)Yes (n)No ";
read entry

echo $name" "$street" "$cityt" "$province } >> adrbook
done

This has worked in every script I have ever written. Hope it works for you!

Chris Ivey
WAN Tools Group
Verizon Data Services
Temple Terrace, Florida

Collapse -

How do I redirect a tab to a file?

by iamsanchez In reply to How do I redirect a tab t ...

Poster rated this answer

Collapse -

How do I redirect a tab to a file?

by iamsanchez In reply to How do I redirect a tab t ...

This question was closed by the author

Back to Linux Forum
7 total posts (Page 1 of 1)  

Related Discussions

Related Forums