Sponsored Content
Top Forums Shell Programming and Scripting Problems with substitution between two variables Post 302701273 by pamu on Saturday 15th of September 2012 11:30:44 AM
Old 09-15-2012
1. Accept two filenames from user and store the filenames in two variables (FILE1 and FILE2)

#You can follow the same with your methods.

2. Check if files exisits. If doesn't, then exit'
Code:
if [[ -e $FILE1 && -e $FILE2 ]] # Check files present or not.
then
#do below operation
else
#exit
fi

3. If files exist, look for a particular string in both files

#To check string present or not..
Code:
if [[ `grep "system hostname" -c $FILE1` -gt 0 ]]
then 
HOSTN=$(awk '/system hostname/{print $3}' $FILE1)
else
#exit 
fi

4. If the string exists, then change the filenames (FILE1 and FILE2) to the string that was looked up in the $3
Code:
mv $FILE1 $HOSTN  #Rename files

5. If string does not exist, then do nothing

#In above if part do exit

6. Build up another filename (FILE3) which is some combination of FILE1 and FILE2
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed substitution problems

Hi falks, I need to substitute in my ksh program, parameter (full path of directory) ,which is sent from outside program, with another parameter (another full path of directory) ,which is known and validated inside my program. I tried to use "sed" ,but i failed. For example: ... (2 Replies)
Discussion started by: nir_s
2 Replies

2. Shell Programming and Scripting

command substitution problems with csh using grep

I am trying to set a command into a variable in a csh script using command substituion with ``. I am having a problem with ps command combined with grep. The command is as follows (shows processes running with the word gpts in them). /usr/ucb/ps axwww | grep gpts this works fine at the... (2 Replies)
Discussion started by: voodoo31
2 Replies

3. Shell Programming and Scripting

Double Substitution variables in ksh

Hi I have a variable whose value is like this i=/test/test1/test2/myfile.cd.070505123457 i would like to have the value of myfile.cd stored into another variable my attempt is test=${i##*/} ;echo $test ##and i get myfile.cd.070505123457 since what i wnat is myfile.cd i try this... (19 Replies)
Discussion started by: xiamin
19 Replies

4. UNIX for Advanced & Expert Users

shell variables and sed substitution

My specific goal: automatically edit a Makefile variable's (EXTRAVERSION) value in a kernel Makefile. So, I have a shell script that takes one parameter, a version string: buildkernel.sh 2.6.18.21.7-custom In the script, I assign the parameter to K_VER: K_VER="2.6.18.21.7-custom"... (2 Replies)
Discussion started by: duderonomy
2 Replies

5. Shell Programming and Scripting

Shell variables problems

hi, i need some help, the situation is this 1-file of variable enviroments DIR1=/tmp DIR2=otherdir/mydir 2-file of list of files (all the names references whic variables of first point) ${DIR1}/${DIR2}/onefile Well now i create a shell script whic... (5 Replies)
Discussion started by: chipcmc
5 Replies

6. Solaris

Shell variables substitution in a file

Hi, I have to read a file and translate the contents including substituting the variables if any and write to another file without using sed or awk. For ex:- inputfile.txt ----------- servername=$SERVER application=$APPL outputfile.txt ------------ servername=actual server name... (2 Replies)
Discussion started by: axes
2 Replies

7. Shell Programming and Scripting

[bash] command line substitution with environmental variables

Hi, I'm using an array that contains compiler FLAGS that need to be executed either before ./configure or after the main 'make' command. example of array containing compiler flags. ------------------------------------------------- FLAGS="CFLAGS=\"-arch x86_64 -g -Os -pipe... (7 Replies)
Discussion started by: ASGR
7 Replies

8. UNIX for Dummies Questions & Answers

sed substitution and shell variables

Hello!! Am trying to substitute the value of a shell variable with the value of another shell variable. The values are obtained into the shell variables through some other processing. for ex. i've used the follow sed command.. sed "s/$var1/$var2/g" i've also tried the other... (5 Replies)
Discussion started by: a_ba
5 Replies

9. Shell Programming and Scripting

Problems with variables syntax

Hi there I am really struggling :eek: to place a value in a variable with the following loop, having run out of ideas please can someone point me in the right direction? We first read two PIDs of a program (say calc) into an array, then we loop reading the details of those processes into a... (6 Replies)
Discussion started by: nathan.harris
6 Replies

10. Shell Programming and Scripting

Bash script having variable substitution problems

Hi I am setting the variables like this : setenv MODULE1 modem5__3 setenv MODULE2 modem5__2 setenv MODULE3 modem_ctrl_1_1 setenv MODULE4 modem_1_0 setenv COUNT 10 I am having a bash script as shown below ################################################ #!/bin/bash for ((... (5 Replies)
Discussion started by: kshitij
5 Replies
COMM(1) 							   User Commands							   COMM(1)

NAME
comm - compare two sorted files line by line SYNOPSIS
comm [OPTION]... FILE1 FILE2 DESCRIPTION
Compare sorted files FILE1 and FILE2 line by line. When FILE1 or FILE2 (not both) is -, read standard input. With no options, produce three-column output. Column one contains lines unique to FILE1, column two contains lines unique to FILE2, and column three contains lines common to both files. -1 suppress column 1 (lines unique to FILE1) -2 suppress column 2 (lines unique to FILE2) -3 suppress column 3 (lines that appear in both files) --check-order check that the input is correctly sorted, even if all input lines are pairable --nocheck-order do not check that the input is correctly sorted --output-delimiter=STR separate columns with STR --total output a summary -z, --zero-terminated line delimiter is NUL, not newline --help display this help and exit --version output version information and exit Note, comparisons honor the rules specified by 'LC_COLLATE'. EXAMPLES
comm -12 file1 file2 Print only lines present in both file1 and file2. comm -3 file1 file2 Print lines in file1 not in file2, and vice versa. AUTHOR
Written by Richard M. Stallman and David MacKenzie. REPORTING BUGS
GNU coreutils online help: <http://www.gnu.org/software/coreutils/> Report comm translation bugs to <http://translationproject.org/team/> COPYRIGHT
Copyright (C) 2017 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. SEE ALSO
join(1), uniq(1) Full documentation at: <http://www.gnu.org/software/coreutils/comm> or available locally via: info '(coreutils) comm invocation' GNU coreutils 8.28 January 2018 COMM(1)
All times are GMT -4. The time now is 11:36 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy