LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 10-29-2008, 03:12 PM   #1
ravi2ray
LQ Newbie
 
Registered: Oct 2008
Location: Kansas, MO
Posts: 9

Rep: Reputation: 0
I need HELP Writing text to a FILE


I am looking for help on writing to a text file:

Lets say i have a file name text.text and i want to echo out "enter name"
then echo "enter age". The collected information i would like to append it to a file that is created when the function is called:

function addText() {

name=$1
age=$2

folder="$HOME/dir/"

fileName=${folder}dir${age}.txt
tempFile=${folder}films${name}Temp.txt

echo "$name" >> $fileName

}

input:
Enter Name: Raymond
Enter Age: 20

next input:

enter name: ray
enter age: 22


the Output inside the file should look like:

"Raymond", "20"
"ray", "22"

... etc
 
Old 10-29-2008, 03:17 PM   #2
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 14,244

Rep: Reputation: 2475Reputation: 2475Reputation: 2475Reputation: 2475Reputation: 2475Reputation: 2475Reputation: 2475Reputation: 2475Reputation: 2475Reputation: 2475Reputation: 2475
Quote:
Originally Posted by ravi2ray View Post
I am looking for help on writing to a text file:

Lets say i have a file name text.text and i want to echo out "enter name"
then echo "enter age". The collected information i would like to append it to a file that is created when the function is called:

... etc
"Captain, sensors indicate a class 4 homework alert ahead...."
 
Old 10-29-2008, 07:06 PM   #3
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,251

Rep: Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025
http://catb.org/~esr/faqs/smart-questions.html
http://www.linuxquestions.org/linux/rules.html
 
Old 10-29-2008, 10:09 PM   #4
ravi2ray
LQ Newbie
 
Registered: Oct 2008
Location: Kansas, MO
Posts: 9

Original Poster
Rep: Reputation: 0
[QUOTE=TB0ne;3325347]"
Captain, i am working in a project which is almost done. I need to learn how to do things differently in order to become better.

This peace of code works but i don't like it:

echo "$age" >> some.txt
 
Old 10-29-2008, 10:10 PM   #5
ravi2ray
LQ Newbie
 
Registered: Oct 2008
Location: Kansas, MO
Posts: 9

Original Poster
Rep: Reputation: 0
Thank you. These links are helpful.
 
  


Reply

Tags
write


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with writing in a text file in C manolakis Programming 5 12-06-2006 10:18 PM
writing text to the beginning of a file linuxmandrake Linux - Newbie 3 03-26-2006 10:55 PM
vb.net writing to a specific line in a text file mrobertson Programming 3 12-30-2005 10:24 PM
Writing to a specific line in a text file mrobertson Programming 6 12-30-2005 04:02 PM
Writing to a text file vb.net mrobertson Programming 5 08-04-2005 12:37 PM


All times are GMT -5. The time now is 07:25 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration