Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
hey i have a doubt, suppose in the script i include an exe type of file for ex. ./a.out, which takes input as a pdb file namely 1sn3.pdb, now i want my output text file to contain the name 1sn3.txt , how do i do that using the shell script ???
is there any method ???? or any command ???
While running or when starting? Both need a different approach.
For the first one read <var> comes to mind.
The second one can be done in several ways, but script <inputfile> is often used. The name of the inputfile is represented as $1 ($2 being the second option, $3 being the third. I.e: script file1 file2 file3).
Although you can use $1 in all of the script, for readability you transfer it to a "human readable" variable (inputfile="$1") and work with inputfile in the rest of the script.
These questions seem to be hypothetical, if you want a good guide to bash scripting take a look here: Advanced Bash-Scripting Guide.
Based on Druuna's comments your bash script would look like this:
fullFileName="1sn3.pdb"
newFileName="${fullFileName%.*}.txt"
./a.out fullFileName > newFileName # assuming that a.out outputs to stdout as plain text output
Your script could also read a file containing a list of .pdb filenames - in that case the above sample would need to go into a loop sequence until all entries are processed.
hey i have a doubt, suppose in the script i include an exe type of file for ex. ./a.out, which takes input as a pdb file namely 1sn3.pdb, now i want my output text file to contain the name 1sn3.txt , how do i do that using the shell script ???
is there any method ???? or any command ???
#!/bin/bash
# clear the screen
clear
# echo question and ask (read) answer
echo ""
echo -n "Enter filename : "
read fileName
# strip all after last dot (xxxx.aa -> xxxx)
newFileName="${fileName%.*}"
# echo new name to screen
echo "New filename is : ${newFileName}"
Testrun:
Code:
$ ./tets.sh
(screen is cleared)
Enter filename : 1d6a.pdb
New filename is : 1d6a
while read a <&6 # read a line from file1
do
read b <&6 # read the 2nd line from file1
echo "$a" >> prt1 # print both lines from file1
echo "$b" >> prt1
echo "$b" >> prt1
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.