LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 07-19-2006, 04:15 AM   #1
procfs
Member
 
Registered: Jan 2006
Location: Sri Lanka
Posts: 651

Rep: Reputation: 34
Need help no editing a file through a script


HI

I have a file called 123 and say the content is

#!/bin/bash
#your name
#T1 is the name
#Example NAME=$asanka
NAME=$T1

#Your Prefix
#T2 is your title
#example TIT=$Mr
TIT=$T2

#Your Surfix
#T3 is your surname
#Example SIR=$Tom
SIR=$T3


Now by running a script say details.sh

enter your name:
enter your Tittle:
enter your Surname:

with this details how can I edit or insert T1, T2, T3 with what the user enters

regards

Asanka

Last edited by procfs; 07-19-2006 at 04:16 AM.
 
Old 07-19-2006, 04:18 AM   #2
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
primalA$ read T1
hello
primalA$ echo $T1
hello
 
Old 07-19-2006, 04:19 AM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
Code:
echo enter your name:
read T1
echo hello $T1

Last edited by bigearsbilly; 07-19-2006 at 05:07 AM.
 
Old 07-19-2006, 04:37 AM   #4
procfs
Member
 
Registered: Jan 2006
Location: Sri Lanka
Posts: 651

Original Poster
Rep: Reputation: 34
I want to edit the file 123 on the fly using a script which will ask user input
 
Old 07-19-2006, 05:07 AM   #5
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
Code:
echo enter your name:
read T1
echo hello $T1
perl -ip.bak "s/T1/$T1/g" file_123
 
Old 07-19-2006, 05:16 AM   #6
procfs
Member
 
Registered: Jan 2006
Location: Sri Lanka
Posts: 651

Original Poster
Rep: Reputation: 34
Its geves mae this error

[root@poseidon test]# ./321
enter your name:
Asanka
hello Asanka
Can't open perl script "s/T1/Asanka/g": No such file or directory
 
Old 07-19-2006, 05:31 AM   #7
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
This is probably better...

Script
Code:
echo enter your name:
read T1
echo enter your Tittle:
read T2
echo enter your Surname:
read T3

# redirect to new file probably best option
m4 -Uindex -DT1="$T1" -DT2="$T2" -DT3="$T3" 123 # > outputfile
TEMPLATE remove the $ (Dollar) signs first...
Code:
#!/bin/bash
#your name
#T1 is the name
#Example NAME=$asanka
NAME=T1

#Your Prefix
#T2 is your title
#example TIT=$Mr
TIT=T2

#Your Surfix
#T3 is your surname
#Example SIR=$Tom
SIR=T3
Result
Code:
billym.primadtpdev>bash asanka 
enter your name:
billy
enter your Tittle:
mr
enter your Surname:
boy  
#!/bin/bash
#your name
#T1 is the name
#Example NAME=$asanka
NAME=billy

#Your Prefix
#T2 is your title
#example TIT=$Mr
TIT=mr

#Your Surfix
#T3 is your surname
#Example SIR=$Tom
SIR=boy
 
Old 07-19-2006, 05:59 AM   #8
procfs
Member
 
Registered: Jan 2006
Location: Sri Lanka
Posts: 651

Original Poster
Rep: Reputation: 34
Hay bigearsbilly

Thanks

Best Regards

Asanka
 
  


Reply



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
text editing from a script vogelbaugh Linux - General 2 09-22-2005 12:53 PM
Editing video_dvd.script webwolf70 Linux - Software 1 08-15-2004 04:39 PM
Editing Shutdown Script coolamit78 Red Hat 2 09-14-2003 06:22 AM
Specifying a variable without editing my script everytime MasterC Programming 6 04-23-2003 08:09 PM
file editing in a bash script Harpune Programming 4 11-22-2002 11:35 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:53 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration