Maybe the following will help you get what you need. It was written and tested using a Korn shell, but will work with any shell that understands basic POSIX required parameter expansions.
If you invoke this script with not operands, it will try to update a file named SAMPLE.txt. If you invoke it with an operand, it will use the 1st operand as the pathname of the file to be updated.
If someone else wants to try this on a Solaris/SunOS system, change awk in the script to /usr/xpg4/bin/awk (nawk won't work for this script).
With the SAMPLE.txt file you provided as an input file, the awk output is:
and the spots indicated above in SAMPLE.txt are changed from ********** to 0000000000, and a DOS <CR><NL> is added to the end of SAMPLE.txt to complete the incomplete line.
And, if you uncomment the line shown in red in the script, it will convert DOS format lines in the input file into UNIX format lines.
You run it just like you run any other shell script:
You copy the text of the script into a regular file with a name that you choose (let us use the name my_script for this example) using an editor that uses the <newline> character as a line terminator (not the DOS <carriage-return><newline> character pair line terminator).
You execute the command: chmod +x my_script to make your script executable.
And then you run your script.
How you run your script depends on what directory you are in, what directory my_script is in, and what file you want your script to process.
The part of the line in the script:
shown in red names the file that will be processed when you run this script if you do not specify an operand. If you want to process a file other than this default, you will specify the name of the file you want to process as the command-line argument when you invoke your script. If the file you want to process is in the directory you are sitting in when you run your script, the argument can just be the last component of the file's name; otherwise you will have to supply an argument that is an absolute or relative pathname (relative to the directory you are in when you run the script).
If you are in the directory where your script is located, you can invoke it with:
to run it to process the default file, or with:
to process a file with the given pathname.
If your script is located in a directory that is on the command search path specified by your PATH environment variable, you can invoke it with just:
or:
And, if your script is not in the current directory and is not on your search path, you can invoke it using the absolute pathname of your script or a pathname of script relative to the directory in which you are sitting:
or:
or:
That worked! I was able to call it from my main script & write to the log file for the main script. I was able to send it in an email also!
Thank you!
I'm glad it worked for you.
Note that if you find a post particularly helpful in achieving your goal or helping you to understand how to get your shell or operating system to do what you want, you can hit the Thanks button at the lower left corner of that post to express your thanks to the person who submitted it.
Hi.
I need to append/prefix an & character to every 'single' & character (not when there are 2 or more grouped together) I find in a file. I can do it using this cmd:
cat ${file} | sed -e 's/&/&&/g' > ${new_file}
How can I modify this to ensure I only replace single &'s and not operate... (11 Replies)
The content of the file filea.txt is as follows.
---------
case $HOSTNAME in
aaa)
DS_PARM_VALUE_SET=vsDev
APT_Configuration_File=/appl/infoserver/Server/Configurations/2node.apt
;;
bbb)
DS_PARM_VALUE_SET=vsQA... (3 Replies)
Hello All,
I need a sed command to find and replace below text in multiple files in a directory.
Original Text :- "$SCRIPT_PATH/files"
Replace with :- "$RESOURCE_FILE"
Thank you in advance !!!
Regards,
Anand Shah (1 Reply)
Hi All,
I have a file having one line only.
It is like
trapsess:inform|10.232.167.18|1|1|50|25|0|0|0|5|1|1|78|0037|
I want to replace the numbers in last two columns by As.
It should look like
trapsess:inform|10.232.167.18|1|1|50|25|0|0|0|5|1|1|AA|AAAA|
Please, suggest me any shell... (12 Replies)
Hello,
I have this command and it works fine.
My question is that how can we replace the N by a variable, to print for instance a big number of lines. It means if I want 100 lines after an expression, to not put "N" 100 times in the sed.
Code:
$ sed -n '/aaa/{n;N;N;s///g;s/;/; /g;p;}'... (2 Replies)
Okay, title is kind of confusion, but basically, I have a lot of scripts on a server that I need to replace a ps command, however, the new ps command I'm trying to replace the current one with pipes to sed at one point. So now I am attempting to create another script that replaces that line.
... (1 Reply)
Hi
I am very new to linux and scripting.
I need to replace numbers abc with number xyz inputting from a reference file.
I used the following command -
sed "s/$grd/$lab/" , where $grd and $lab comes from reference file.
The problem is the above line doesnt take care of space..... (1 Reply)
Hi,
I would like to seek help on how i can arrive on this result.
sample.txt:
product_code IN (param001) and product_type IN (param004)
product_code IN (param002) and product_type IN (param005)
product_code IN (param003) and product_type IN (param006)
I would like to change the param001... (1 Reply)