First off, thank you for using the code-tags. Yours didn't work because you can enter them either all caps ("CODE") or all small ("code"), but not mixed case. I changed that for you.
Regarding your problem: The loop would cover the case when your file1 would contain several lines and you use grep to single out ONE OR SEVERAL of them and replace any occurrence in file two with one after the other. Lets do an example:
File 1
File 2
Program:
When you only execute the "grep 'use' file1" you will see that it filters out all the lines starting with "ignore" and only displays the one with "use". The variable "source" will be given each of these lines as a content successively at every single execution of the loop:
1) set variable source to "use first"
2) execute "sed '/target/use first/' file2 > file2.tmp"
3) execute mv file2.tmp file2
4) set variable source to "use second"
5) execute "sed '/target/use second/' file2 > file2.tmp"
6) execute mv file2.tmp file2
7) set variable source to "use fourth"
8) execute "sed '/target/use fourth/' file2 > file2.tmp"
9) execute mv file2.tmp file2
...and so on
As you can see all the occurrences of "target" will be changed to "use first" in step 2. Step 5, step 8, etc. will have nothing to do at all.
Therefore the only sensible reasoning for your problem is that "file1" contains only one line from the beginning (that is: only one line which is matched by the grep). In this case you don't need to loop at all (because a loop which is executed only once anyway is unnecessary) and therefore you could rewrite your script like this:
Hi Experts,
I am writing a python script to grep string from file and display output in csv file as in attached screenshot
https://drive.google.com/file/d/1gfUUdfmQma33tz65NskThYDhkZUGQO0H/view
Input file(result_EPFT_config_device)
Below is the python script i have prepared as of... (1 Reply)
One more question:
I want to grep "COS_12_TM_4 pattern from a file look likes :
"COS_12_TM_4" " ];I am taking scan_out as the input from the user.
How to search "COS_12_TM_4" in the file which is corresponds to scan_out (12 Replies)
I have a file example.txt as follows :SomeTextGoesHere
$$TODAY_DT=20140818
$$TODAY_DT=20140818
$$TODAY_DT=20140818I need to automatically update the date (20140818) in the above file, by getting the new date as argument, using a shell script.
(It would even be better if I could pass... (5 Replies)
Hi All,
Hoping you can help as im in desperate need... I'm very new to unix scripting so apoligies,
I have setup an expect script in order to log into a node on our network, This will provide an output as per the below
*********** information:
*************: n/a
TEST IP : n/a
... (18 Replies)
Hi All,
How do I provide the output of a command to another command which is waiting for an input from the user ?
Ex : I need to login to a device via telnet. In the script, initially I use the "read" command to get the IP Address, Username and Password of the device from the user. Now,... (1 Reply)
I would appreciate any help.
I need to run 'ps -ef | grep 'process', get the process id and kill that process.
I have got this far:
- Get pid using ps -ef | awk '/process/{ print $2}'
after this I'm kind of stuck..
- Use pipe to redirect the output to kill
pid=ps -ef | awk '/bmserver/{... (2 Replies)
Hi guys...
I am new to this scripting...so please forgive me if anything worng in my questions...
here is my question..
I have file structure
/home/oracle/<sid>/logs/bkup
now i want to write a script which should grep the sid name from a file..and it should replace the <SID> with... (1 Reply)
Hi,
I am triying to make sure that there exists only one file with the pattern abc* in path /path/. This directory is having many huge files. If there is only one file then I have to take its complete name only to use furter in my script.
I am planning to do like this:
if ; then... (2 Replies)
Hi guys. Is it possible (I'm sure it is) to use the output of a simple 'ls' command as input of another command 'tail'.
It is not really the output of the 'ls'. I have to useeach line of the output.
This is the first command...
ls *myFile*021308*
Which it outputs many filenames. For each... (3 Replies)
This site has been very helpful thus far.. I thank you all in advance for sharing the knowledge. Let me get to it.
I am trying to write a very small script to take away from the boredom of doing the same thing over and over.
Everynow and again I have to get the hex value of a file using a... (2 Replies)