I have a requirement to read a list of script names create a .finish blank file for each of them.
The script names can be like:
- ScriptName.sh
- ScriptName.sh Param1
- ScriptName.sh Param1 Param2
I need to create files like below using the same script:
- ScriptName.finished
- ScriptName.Param1.finished
- ScriptName.Param1.Param2.finished
Eg ListFile.txt:
I am trying to read these script names in a loop and cut the 3 values to create it.
In first case test1.sh, all three values are given as test1, test1.sh, test1.sh
Since cut has nothing after first space, should it not have the value for par1 and par2 as blank?
I am using ksh. Is there an easier way to do this?
Thanks in advance for the help.
Last edited by Don Cragun; 06-18-2014 at 05:25 PM..
Reason: Add CODE and ICODE tags.
These are much easier to do with variable substitution. It sounds hard to get started, but it's easier when you get the hang of it.
Is SCRIPT_NAME a value you will read as input or do you want it to be the name of the script you are already running? The current running script will be known as $0, parm 1 is $1, parm 2 is $2 etc.
If you are using this, then you can slice the values up however you like, such as:-
You might be wanting to read from an input file as you seem to suggest with your done <"ListFile.txt" so you could also do this:-
Does that help?
Be aware that if you have three parameters, then this while read will put the 2nd & 3rd parameter into $par2
Robin
Last edited by rbatte1; 06-18-2014 at 12:51 PM..
Reason: Added parm3 warning
This is really helpful. Thanks much Robin. Reading the parametes in while loop makes it so much easier.
I will need to check that the par1 and par2 are not blank and create the .finished file.
If both of them are blank, then the file will be say $trimmed.finished, if par1 is present then $trimmed.$par1.finished, if both are present $trimmed.$par1.$par2.finished.
Is an if condition the best way? Or Is there an easier way to check if a variable is null and use it if not don't while appending?
Standard POSIX parameter expansions do everything you seem to want here: ${base%.*} will remove the last period and everything following it from the 1st word on a line in the input file. ${e1:+.$e1} expands to an empty string if the 2nd word on a line from the input file was not present or to a period followed by that word if it was present. ${e2:+.$e2} does the same thing for the 3rd word.
With the ListFile.txt from the first message in this thread, this script will create (or update the timestamps to the current time if they already exist) the files:
These 2 Users Gave Thanks to Don Cragun For This Post:
I am using : << cut / cut to comment out block of code.
Works fine on few lines of script, then it gives me this cryptic error when I try to comment out about 80 lines.
The "warning " is at last line of script.
done < results
169 echo "END read all positioning parameters"
170... (8 Replies)
I have a file with the following format:
X|High|2|GIC|DM||XHM|||6 Months
X|Moderate|2|GIC|DM||XHM|||6 Months
X|High|2|GCM|DM||XSF|||6 Months
X|Med|2|GCM|DM||XSF|||6
Here there are ten columns but I need to print rows having blank records in any of the rows (except for 6th,8th and 9th... (10 Replies)
Hi All
Need Help
I have a file with the below format (ABC.TXT) :
®¿¿ABCDHEJJSJJ|XCBJSKK01|M|7348974982790
HDFLJDKJSKJ|KJALKSD02|M|7378439274898
KJHSAJKHHJJ|LJDSAJKK03|F|9898982039999
(cont......)
I need to write a script where it will check for : blank lines (between rows,before... (6 Replies)
I have below file. I want to remove space at begining of every line and then after also remove blank line from file.
I use below code for each operation.
sed -e 's/^*//' < check.txt > check1.txt
sed '/^\s*$/d' < check1.txt > check2.txt
above code not remove all the space... (12 Replies)
I have file which has more than 1000 lines. PFB file info
Line 1.
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAPSDK1="http://www.w3.org/2001/XMLSchema" xmlns:SOAPSDK2="http://www.w3.org/2001/XMLSchema-instance"... (8 Replies)
Hello,
I am using this to get only directories :
ls -l | grep '^d'and here is the result :
drwx------ 13 so_nic sonic 13 Nov 4 13:03 GLARY
drwx------ 3 so_nic sonic 3 May 6 2010 PSY2R
drwx------ 15 so_nic sonic 15 Oct 14 08:47 PSYR1
But I only need to keep this... (7 Replies)
Hi,
I'm running 2.6.9-55.ELsmp. I'm looking for a script to remove a blank line on the first line of a file. The script must also test if the file is 0k, if yes then do nothing, but if the file is > 0k then check if the first line is not blank, if yes then remove the line then save it.
... (4 Replies)
Hi All,
When i am runing a script from home directory the output is fine, but whenever i am running a script from any of the directory the output is fine while a "Blank file" is created named as "1" in the particular directory.
Will you please suggest any options to fix this problem. It... (1 Reply)
I am calling SQL script in my UNIX Shell script and trying to create the CSV file and my last column value of each row is 23 blank spaces.
In my SQL script,the last column is like below.
RPAD(' ',23,' ') -- Padding 23 blank Spaces
The CSV file is generated but the sapce(23 spaces) is... (2 Replies)