format values in a text file using cat command


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers format values in a text file using cat command
# 1  
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

Image


but here in my code....

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...

Image

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

Thank you so much ^_^

Moderator's Comments:
Mod Comment Please use code tags, thanks.

Last edited by kpopfreakghecky; 08-30-2011 at 04:17 AM.. Reason: code tags
# 2  
Prize for the most pointless use of cat is winging its way to you Smilie
Code:
echo -e "$firstname\t" >>names.txt
...
echo -e "$lastname\n" >>names.txt

# 3  
1. You don't need "cat" command:
Code:
echo "$firstname " >> names.txt

2. 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.
# 4  
Thanks for that but.....

Thanks for that ^_^
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


Image


I want to have an output similar to this photo below


Image


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

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

I tried notepad++

with the following codes

Code:
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++

Image

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

Image

How can that be possible?

Hoping for your help guys .... Thank you so much Smilie
# 5  
You can use
Code:
echo "Enter First Name: "
read firstname
echo -ne "$firstname\t" >> names.txt

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

Or (better):
Code:
echo "Enter First Name: "
read firstname
printf "$firstname\t" >> names.txt

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

# 6  
Hammer & Screwdriver THANK A LOT YUZU!!!! :*

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

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #677
Difficulty: Medium
The IEEE does not test equipment for compliance with their standards.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to change the format of an Excel from exponential to text through UNIX command?

How to change the format of an excel from exponential to text through UNIX command We have a pipe delimited file in which one particular A column is a combination of number+text and while converting into excel using tr command it is generating a exponential data for the A column. Kindly... (2 Replies)
Discussion started by: AbiramiRaja
2 Replies

2. Shell Programming and Scripting

Cat files listed in text file and redirect to new directory with same filename

I have a directory that is restricted and I cannot just copy the files need, but I can cat them and redirect them to a new directory. The files all have the date listed in them. If I perform a long listing and grep for the date (150620) I can redirect that output to a text file. Now I need to... (5 Replies)
Discussion started by: trigger467
5 Replies

3. Shell Programming and Scripting

Read record from the text file contain multiple separated values & assign those values to variables

I have a file containing multiple values, some of them are pipe separated which are to be read as separate values and some of them are single value all are these need to store in variables. I need to read this file which is an input to my script Config.txt file name, first path, second... (7 Replies)
Discussion started by: ketanraut
7 Replies

4. UNIX for Dummies Questions & Answers

Cat command drops lines in output file

I use the cat command to concatenate text files, but one of the rows I was expecting doesn't display in the output file. Is there a verbose mode\logging mechanism for the cat command to help me investigate where the lines I was expecting are going?? cat 7760-001_1_*_06_*.txt | grep -v... (1 Reply)
Discussion started by: Xin Xin
1 Replies

5. Shell Programming and Scripting

How can I read variable text files through cat command?

Hi. I'm just wondering how can I read variable text files through cat command. I made a shell script to count frequency of words and array them with variable conditions. It's only working for one file that I wrote in script now. But I want to make it working for every text file when I execute... (2 Replies)
Discussion started by: rlaxodus
2 Replies

6. Shell Programming and Scripting

Cat Values from Several files if it meets criteria for column values

I have results from some statistical analyses. The format of the results are as given below: I want to select lines that have a p-value (last column) less than 0.05 from all the results files (*.results) and cat to a new results file. It would be very nice if a new column is added that tells... (2 Replies)
Discussion started by: genehunter
2 Replies

7. UNIX for Dummies Questions & Answers

stuck in editing file with cat command

Hi, While editing a small text file with cat command i pressed ctrl-d to send eof, instead of coming out of cat command it echoed ^D to the screen. Same thing is happening to ctrl-c. After googling i found this is because of trap. The problem is i m stuck in editing mode and cannot get the... (3 Replies)
Discussion started by: TITANIUM
3 Replies

8. Shell Programming and Scripting

Identify high values "" in a text file using Unix command

I have high values (such as ) in a text file contained in an Unix AIX server. I need to identify all the records which are having these high values and also get the position/column number in the record structure if possible. Is there any Unix command by which this can be done to : 1.... (5 Replies)
Discussion started by: devina
5 Replies

9. UNIX for Dummies Questions & Answers

Creating File using the CAT Command

Hello , I am newbie to UNIX platform . I have read that there are two ways of creating files that is using 1.) Cat 2.) touch . With Cat Command i am unable to create a File , i is saying No file or Directory exists I logged in with root as user . please help (7 Replies)
Discussion started by: Ravi Pavanv
7 Replies

10. Shell Programming and Scripting

cat in the command line doesn't match cat in the script

Hello, So I sorted my file as I was supposed to: sort -n -r -k 2 -k 1 file1 | uniq > file2 and when I wrote > cat file2 in the command line, I got what I was expecting, but in the script itself ... sort -n -r -k 2 -k 1 averages | uniq > temp cat file2 It wrote a whole... (21 Replies)
Discussion started by: shira
21 Replies

Featured Tech Videos