09-23-2008
Need help with some iterative file processing
Gurus - Please help with this urgent situation.
I have the following problem to solve using a shell script:
1. There are about 13 files named CONTAINER_1.lst, CONTAINER_2.lst, CONTAINER_3.lst .....CONTAINER_13.lst
2. Each of these files contain about 8 lines (in most cases) containing container instance names like CONTAINER_X_InstanceY where X will correspond to the container in question (ranging from 1 thru 13) and Y is some random variable value
3. For each of the 13 containers, there is a file named, CONTAINER_X_commands.sh where X corresponds to the container number. Each of the CONTAINER_X_commands.sh file contains about 3 to 5 commands with a fixed embedded string called "HELLOWORLD"
4. For each container name, I would like to first read all the CONTAINER_X_InstanceY variables (one at a time), then repeat each of command in the CONTAINER_X_commands.sh file, N number of times where N is the number of lines in the CONTAINER_X.lst (equal to the number of container instances) Once the yanking/creating multiple copies of commands is done, I would like to replace each occurrence of the "HELLOWORD" string with CONTAINER_X_InstanceY container instance name variable
Here is the code I have written so far :
for container_list in `ls -1 CONTAINER*.lst | sort -u`
do
container_name=`echo $container_list | sed 's;\(.*\)\..*;\1;'`
cmd_suffix=_commands.sh
command_file=$container_name$cmd_suffix
for container_instance_name in `cat $container_list`
do
for command in `cat $command_file`
do
echo $command | sed 's/HELLOWORLD/$container_instance_name/g;' >> /tmp/all_commands_in_singlefile.lst
done
done
done
There are 3 problems in my output :
1. It's printing each word in the commands.sh file on separate line. I would like to keep each command intact on it's own line without breaking each command word on separate line (I think this is an issue with my innermost for loop)
2. the sed is actually replacing HELLOWORLD with the literal string "$container_instnace_name" instead of using the actual variable value
3. I am also suspecting that the output file is containing lesser number of rows of commands, than I would actually anticipate. But this is yet to be substantiated because of newlines introduced in my output.
Any help will be greatly appreciated!
indi
9 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I have a shell script that runs all the time looking for a certain type of file and then it processes the file through a series of other scripts. The script is watching a directory that has files uploaded to it via SFTP. It already checks the size of the file to make sure that it is not still... (3 Replies)
Discussion started by: heprox
3 Replies
2. Shell Programming and Scripting
grep -o '\{1,3\}\.\{1,3\}\.\{1,3\}\.\{1,3\}' then how do i iterate the file names?? (19 Replies)
Discussion started by: ravis83
19 Replies
3. Shell Programming and Scripting
Hi I am new to shell scripting and trying to get values from a text file,
I have a text file with values seperated with "|". like
aga|120220090525|120220090525|120220090525|120220090530
bab|120220090530|120220090530|120220090535|120220090535|120220090535... (4 Replies)
Discussion started by: mannepalli
4 Replies
4. Shell Programming and Scripting
Hello,
say suppose i am processing an file emp.dat the field of which are
deptno empno empname etc
now say suppose i want to change the file to emp.lst then how can i do it? Here i what i attempted but in vain
BEGIN{
system("sort emp.dat > emp.lst")
FILENAME="emp.lst"
}
{
print... (2 Replies)
Discussion started by: salman4u
2 Replies
5. Shell Programming and Scripting
Hello everybody,
I have a little problem with one of my program. I made a plugin for collectd (a stats collector for my servers) but I have a problem to make it run in parallel.
My program gathers stats from logs, so it needs to run in background waiting for any new lines added in the log... (0 Replies)
Discussion started by: Samb95
0 Replies
6. Shell Programming and Scripting
I have always struggled when parsing a file vertically vs. by line horizontally. Can't seem to get my head around the concept. Here again I need to convert vertical output to horizontal output.
original output
root@acuransx:bpplsched 2000-STAND3 -v -M acuransx -l
<2>bpplsched: INITIATING:... (4 Replies)
Discussion started by: jouuu
4 Replies
7. Shell Programming and Scripting
Hi All,
The script below read the path and searches for the directories/subdirectories and for the files. If files are found in the sub directories then read the content of the all files and put the content in csv(comma delimted) format and the call the write to xml function to write the
std... (1 Reply)
Discussion started by: Optimus81
1 Replies
8. Programming
Hello,
I extracted a list of files in a directory with the command ls . However this is not my computer, so the ls functionality has been revamped so that it gives the filesizes in front like this :
This is the output of ls command : I stored the output in a file filelist
1.1M... (5 Replies)
Discussion started by: ajayram
5 Replies
9. UNIX for Dummies Questions & Answers
I have one input file ABC.txt and one output DEF.txt. After the ABC is processed and created output, I want to rename ABC.txt to ABC.orig and DEF to ABC.txt. Currently when I am doing this, it does not process the input file as it cannot read and write to the same file. How can I achieve this?
... (12 Replies)
Discussion started by: High-T
12 Replies
LEARN ABOUT OPENSOLARIS
prtfru
prtfru(1M) System Administration Commands prtfru(1M)
NAME
prtfru - print FRUID-specific information about the FRUs on a system or domain
SYNOPSIS
/usr/sbin/prtfru [-d] | [-clx] [container]
DESCRIPTION
The prtfru utility is used to obtain FRUID data from the system or domain. Its output is that of a tree structure echoing the path in the
FRU (Field-Replaceable Unit) tree to each container. When a container is found, the data from that container is printed in a tree-like
structure as well.
prtfru without any arguments will print the FRU hierarchy and all of the FRUID container data. prtfru prints to stdout which may be redi-
rected to a file.
OPTIONS
The following options are supported:
-c Prints only the containers and their data. This option does not print the FRU tree hierarchy.
-d Prints a DTD for the current registry to stdout.
-l Prints only the FRU tree hierarchy. This option does not print the container data.
-x Prints in XML format with a system identifier (SYSTEM) of prtfrureg.dtd.
Options -c and -l can be used together to obtain a list of the containers.
OPERANDS
The folowing operand is supported:
container The name of a particular container in the FRU hierarchy, that is, either the name or path/name of a container as displayed in
the -l option.
EXIT STATUS
The following exit values are returned:
0 All information was found and printed successfully.
>0 An error has occurred.
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|Availability |SUNWfruid |
+-----------------------------+-----------------------------+
SEE ALSO
fruadm(1M), attributes(5)
SunOS 5.11 30 May 2002 prtfru(1M)