Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 01-13-2008, 03:14 PM   #1
LQ Newbie
Registered: Jun 2007
Posts: 9

Rep: Reputation: 0
wanna to save the input to a file

am currently working with shell scripting in Linux and this is what.. I wanna to achieve..

I have a file named "a" having some parameters in it. for ex: color= red and boys = 10.
Now, I wanna to run a script, so that It will ask the values of color and boys from me to input,.
I will then enter color-green and boys=12.

Then it will update those values into the file "a".

So that, when I will open the file :"a".. I will find the update values of color and boys as green and 12 respectively.

As per my understanding, we need to locate the address of variable color and boys that were stored the values as red and 10 respectively earlier.
Then we need to replace those values as green and 12 to that memory location.

Kindly suggest me, if this will work or you have different opinion.
Thanks for your time ... and sorry to distrub you... Hope you don't mind..

Old 01-13-2008, 04:35 PM   #2
Registered: May 2004
Location: Iowa USA
Distribution: CentOS
Posts: 419

Rep: Reputation: 30
You haven't said what shell, but here's an idea in bash:


echo -n "Enter color: "
read new_color
echo -n "Enter number of boys: "
read new_boys

sed -i s/color=.*/color=$new_color/ lq.txt
sed -i s/boys=.*/boys=$new_boys/ lq.txt
root@beren [~/scripts/shell]# cat lq.txt
root@beren [~/scripts/shell]# ./
Enter color: blue
Enter number of boys: 12
root@beren [~/scripts/shell]# cat lq.txt
root@beren [~/scripts/shell]#
Far and away not perfect; consider a different output file:
root@beren [~/scripts/shell]# cat lq.txt
root@beren [~/scripts/shell]# ./
Enter color: blue
Enter number of boys: 12
root@beren [~/scripts/shell]# cat lq.txt
root@beren [~/scripts/shell]#
But it's a start. Based on the contents of the output file, you will need to adjust the regular expressions you use with sed.

Hope that helps.
Old 01-13-2008, 08:15 PM   #3
LQ Guru
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 8,629
Blog Entries: 4

Rep: Reputation: 2999Reputation: 2999Reputation: 2999Reputation: 2999Reputation: 2999Reputation: 2999Reputation: 2999Reputation: 2999Reputation: 2999Reputation: 2999Reputation: 2999
Well, it might also be even simpler than that.

"Every Linux/Unix program" has the notion that it reads its input from STDIN, writes its output to STDOUT, and sends its error-messages to STDERR. All three of these names are abstract names: you can define, on the fly, what these input-files belong to.

By default, STDIN will be "your terminal" and both STDOUT and STDERR will also be "your terminal."

Now, let's say that this time when I run my program, I want to read the input from one file, write the output to another, and simply dispose-of any errors.
 myprogram <inputfile >outputfile 2>/dev/null
("/dev/null" is a pseudo-device that consumes anything written to it. The "bit-bucket...")

What if we'd like to pipe the output of one program straight into the mouth of another one? Easy:
 foo | bar
"Get to know the Unix shell(s)." The time will be well-spent.
Originally Posted by Dorothy
I don't think we're in Redmond anymore, Toto...


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
save file from std input khairilthegreat Linux - Newbie 3 08-13-2007 03:04 AM
[Perl] - save input in .html file noir911 Programming 2 01-07-2007 03:36 PM
Hint: Wanna try Linux, so wanna rig your Windows system to dual-boot? sundialsvcs Linux - Newbie 2 08-16-2005 03:56 PM
Mozilla 1.7 - No File Save / File Open dialogs on Slackware 10.0 jayseye Slackware 8 08-10-2004 06:52 AM
i installed mplayer from source file and now i wanna delete it from my computer ... SlackwareMan Linux - Software 6 07-30-2004 08:40 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:40 AM.

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