Bash script to replace text file from a lookup file
Hi. I need assistance with the replacing of text into a specific file via a bash script.
My bash script, once run, currently provides a menu of computer names to choose.The script copies onto my system various files, depending what computer was selected in the menu.This is working OK.
Now, I need to update certain other files depending on what computer was selected.I have created an example scenario below.
I have a file called mainfile.txt and a lookup file called lookupfile.txt.
If I run my script and chose the option for Computer A, a variable is set in my script, e.g. $ComputerA
What I now need is for the ‘DomainName=’ in my mainfile.txt to update with the full domain name of ComputerA that’s detailed in the lookupfile.txt
Lookupfile.txt Mainfile.txt
From researching the issue I believe I can use awk or sed.However, I have had difficulty finding examples like I to get it working.
Can anyone provide a solution (and possibly an explanation of the solution).I can re-format my lookup.txt file if required Many thanks.
Last edited by Don Cragun; 03-22-2015 at 04:55 PM..
Reason: Get rid of dozens of font and size tags; add CODE tags.
Please use code tags as required by forum rules!
Did you consider searching these fora for examples?
Your lookup file doesn't have any field separators, so a translation might run into trouble.
Given your table had <TAB> field separators,
could do what you want. Use command substitution to assign to a variable.
In the bash below the user selects the file to be used. The digits of each file are unique and used to automatically locate the next file to be used in the process. The problem I can not seem to fix is that the full path needs to be referenced in the second portion and it is not currently. Is... (7 Replies)
I'm working on a new exercise that calls for a script that will take in two arguments on the command line (representing the range of line numbers) and will subsequently print those lines from a a specified file. Command line would look like this: ./lines_script.bash 5 15 <file.txt. The script would... (8 Replies)
I have a list of hostnames in a txt file . I need to do nslookup or other command on linux and get the ip address and if you dont find an ip address then put 0.0.0.0 instead in the output text file along with the hostname.
So input
host1
host2
host2.dd.ddd.net
Output
host1,... (2 Replies)
Hi All,
I don't know how to fast do this field replace that need lookup from another file to form the update result:confused:
I want to do it by general shell script
Can anyone help to solve it ? Thanks for your kindly reply in advance.
CK (0 Replies)
Hi Folks,
I have an html file which contains the below line in the body tagI am trying the replace hello with Hello Giridhar programatically.
<body>
<P><STRONG><FONT face="comic sans ms,cursive,sans-serif"><EM>Hello</EM></FONT></STRONG></P>
</body>
I have written the below code to... (3 Replies)
Hi
I am new to unix and newbie to this forum. I need help in writing a gawk script that search and replace particular text in a flat file.
Input file text :
ZIDE_CONTROL000 100000000003869920900000300000001ISYNC 000002225489 0000000002232122 20120321 16:40:53
ZIDE_RECORD000... (5 Replies)
Hi,
I have files with names in the following naming pattern,
Name.of.moviemoretext-moretext.mov
or
Name of moviemoretext-moretext.mov
And I would like to delete the and moretext-moretext leaving just the Name of movie.
The Name of movie will always be different and the year will... (4 Replies)
Write a quick shell snippet to find all of the IPV4 IP addresses
in any and all of the files under /var/lib/output/*, ignoring
whatever else may be in those files. Perform a reverse lookup on
each, and format the output neatly, like "IP=192.168.0.1,
... (0 Replies)
Hi
I have two files a1 and b1
a1 has the following job names
ab
cd
ef
b1 has the following job details
/*----------- ji -----------------*/
asdasd fgd
saas dfdf
asas fd gfg
/*---------- ab ----------------*/
ara jhk
dfhk asjla
condition: s(abc_wf_hi) (10 Replies)
I have a file something like this (except much larger amount of rows/data)
0001 blue testing1
0002 blue testing2
0006 blue testing3
0232 red testing4
2143 blue testing5
3453 blue testing6
In a script I want to replace the word red with blue where the line begins with a... (4 Replies)