Please become accustomed to provide decent context info of your problem.
It is always helpful to carefully and detailedly phrase a request, and to support it with system info like OS and shell, related environment (variables, options), preferred tools, adequate (representative) sample input and desired output data and the logics connecting the two including your own attempts at a solution, and, if existent, system (error) messages verbatim, to avoid ambiguities and keep people from guessing.
man bash:
Quote:
Process Substitution
. . . If the <(list) form is used, the file passed as an argument should be read to obtain the output of list.
I have no idea how you arrived at this, but if this would work, shell programming woud be a bad idea. ;-)
First: forget about backticks. They are just there for backwards compatibility with a shell which is not in use any more since about 25 years. Just forget they exist.
Second: even if you use backticks, x=`some -command` is a variable assignment. In fact it does: run the command some -command and assign its output to variable x. So, what you did amounts to:
which is obviously not what you intended. You do it the same way i showed you with sed: by pipelining it like this:
The pipeline can have more than one part, so this would also be possible:
This runs command1, then pours its output into command2, the output of command2 into command3 and so forth, until the output of the last command is poured into the loop, which reads it line by line and processes it.
I am sure you can now construct your own script with ease, no?
By the way: if you want to process lines like you do stay generally away from for-loops. While-loops are a lot more flexible when it comes to parsing input, even when word-splitting is involved.
Suppose you have a file (or process output, which is effectively the same) of this structure:
and you want to process the second word of every line ("line1-word2", "line2.word2", etc.) then this will do it:
Try it out. You could do that with some gymnastics and a for-loop too, but this is IMHO a lot easier to write and a lot easier to read and understand.
Please become accustomed to provide decent context info of your problem.
It is always helpful to carefully and detailedly phrase a request, and to support it with system info like OS and shell, related environment (variables, options), preferred tools, adequate (representative) sample input and desired output data and the logics connecting the two including your own attempts at a solution, and, if existent, system (error) messages verbatim, to avoid ambiguities and keep people from guessing.
man bash:
What do you think is the output of
?
Sure RudiC,will make a note of it.
---------- Post updated at 03:15 PM ---------- Previous update was at 03:13 PM ----------
Quote:
Originally Posted by bakunin
I have no idea how you arrived at this, but if this would work, shell programming woud be a bad idea. ;-)
First: forget about backticks. They are just there for backwards compatibility with a shell which is not in use any more since about 25 years. Just forget they exist.
Second: even if you use backticks, x=`some -command` is a variable assignment. In fact it does: run the command some -command and assign its output to variable x. So, what you did amounts to:
which is obviously not what you intended. You do it the same way i showed you with sed: by pipelining it like this:
The pipeline can have more than one part, so this would also be possible:
This runs command1, then pours its output into command2, the output of command2 into command3 and so forth, until the output of the last command is poured into the loop, which reads it line by line and processes it.
I am sure you can now construct your own script with ease, no?
By the way: if you want to process lines like you do stay generally away from for-loops. While-loops are a lot more flexible when it comes to parsing input, even when word-splitting is involved.
Suppose you have a file (or process output, which is effectively the same) of this structure:
and you want to process the second word of every line ("line1-word2", "line2.word2", etc.) then this will do it:
Try it out. You could do that with some gymnastics and a for-loop too, but this is IMHO a lot easier to write and a lot easier to read and understand.
I hope this helps.
bakunin
Bakunin, Thanks a ton for your detailed explanation.I will try to construct my script now!
I am facing one more challenge here, for time being i have passed the variable from a file line by line and it is working fine but i have some 2k names in the file so i need to make checkpoint at 100 each time and then start executing the steps till end of the file. For example, my script should consider the first 100 names line by line,passing it as a parameter and execute the code. and the when i execute it next time it should skip the first 100 lines and pick it from 101 line till 200..
There are umpteen possible approaches to your last question, e.g. using a counter in the loop, splitting the input file, using nested loops, mayhap a dedicated script.
Why don't you present your script and input data, and we'll discuss?
I have a test file with the following format, It contains the username_date when the user was locked from the database.
$ cat lockedusers.txt
TEST1_21062016
TEST2_02122015
TEST3_01032016
TEST4_01042016
I'm writing a ksh script and faced with this difficult scenario for my... (11 Replies)
Hi,
I am calling a Perl script in my shell script. When Perl script is executed it asks for a answer to be entered by user from terminal. How can i pass that value from my shell script ??
I know I can change perl script to default the answer but i dont have access to do that so only option i... (5 Replies)
Hi. I'm trying to write a script that reads a line on a file and runs a different command for a different line output.
For example, if it finds the word "Kuku" on the line it sends mail to Kuku@kuku.com. Otherwise, it sends mail to Lulu@lulu.com.
TIA. (2 Replies)
Hello, I am quite new in shell scripting and I would like to write a little scritp to run a program on some parameters files.
all my parameters files are in the same directory, so pick them up with
ls *.para >>dirafter that I have a dir file like that:
param1.para
param2.para
etc...
I... (2 Replies)
When I run this:
PDHDURL=`/usr/bin/curl --silent http://www.phdcomics.com/comics.php | /usr/bin/grep -o http://www.phdcomics.com/comics/archive/.*.gif | head -1`
echo -e "$PHDURL"
It is totally blank. However, when I just run it from the terminal:
/usr/bin/curl --silent... (2 Replies)
Hi,
I had written a shell script to pass command line argument to variable in a function.
Here is my code:
main
if ; then
.$1
echo $1
get_input_file
else
echo "input file $1 is not available"
fi
get_input_file()
{
FILE = "$1"
echo $FILE
} (10 Replies)
Hello
I am using unix CLI commands for the Synergy CM software. The command basically searches for a folder ID and returns the names of the projects the folder sits in. The result is assigned to a variable:
FIND_USE=`ccm folder -fu -u -f "%name"-"%version" ${FOLDER_ID}`
When the command... (6 Replies)
Hi, I am trying to write a ftp script which will read a file for filenames and ftp those files to another server. Here's my ftp script, but it's scanning the current directory for file names.
My question is how can I pass multiple files (these files will have the name of data files that need to... (0 Replies)