First let me explain the scenario
I have tywo files as usual
file1.txt (it has n rows and 8 columns)
$1 $2 $3 $4 $5 $6 $7 $8
Code:
we have to consider here $5 , $6 , $7 for our search
file2.txt (it has n rows and 6 columns)
$1 $2 $3 $4 $5 $6
Code:
here we should take only $2 for comparison. As you can most of the $2 field records has value and some do not have value
Question:
I want to take the fields $5 , $6 , $7 from file 1 and compare it with $2 field from file 2. and the rsult should be like this
Code:
if $5 (file1) =$2 (file2) then replace $5 (file1) with $1 of (file2)
if $6 (file1) =$2 (file2) then replace $6 (file1) with $1 of (file2)
if $7 (file1) =$2 (file2) then replace $7 (file1) with $1 of (file2)
the final output will look like this
Actual file1.txt (before running the code)
$1 $2 $3 $4 $5 $6 $7 $8
Code:
FIle1.txt after running the above said condition
$1 $2 $3 $4 $5 $6 $7 $8
Code:
so the field $5 , $6 , $7 should get replaced from the matched valued of $1(file1)
Now for this i got the below code running in Bash 4.1 version perfectly
But the real problem occurs when i run the above code in system which is of bash version 3.00.16(1)-release (sparc-sun-solaris2.10)
I get error as man.sh: syntax error at line 3: `array1=' unexpected
Please help me in fixing this array error sooner as it is critical for me now , so that the script runs even in the 3.0 version too.
Last edited by Franklin52; 05-09-2011 at 04:18 AM..
Reason: Please use code tags
If your version of bash doesn't have arrays, there's not a lot to be done for that.
Do you have ksh available? You could initiailize an array in it like
set -A array1 $(echo "$line1" | sed -e 's/|/ /g')
You don't need to run sed once on each and every individual line by the way! That's not very efficient. Just set IFS="|" and then the shell will split on that, both in the BASH and KSH methods.
Oh ok. I tried in many possible ways yesterday and finally ended up in getting super confused. Thanks for the clarification can you please remodel the code in the way which is efficient and run on ksh.
Please help me out in fixing this script as it is very critical for my work
Hi Ive been trying for days now and i just cannot work this out.
Can someone please tell me if im doing this right.
I've written some python3.3 code and now i want to transfer it to an embedded computer to execute.
My OS is a : Debian GNU/Linux 6.0.7 (squeezez) 32-bit kernel
The... (1 Reply)
Hi Ive been trying for days now and i just cannot work this out.
Can someone please tell me if im doing this right.
I've written some python3.3 code and now i want to transfer it to an embedded computer to execute.
My OS is a : Debian GNU/Linux 6.0.7 (squeezez) 32-bit kernel
... (0 Replies)
I have the following ksh-script:
#!/bin/ksh
# Ueberprüfe, ob genau ein Parameter angegeben wurde
test "$#" -eq "1" || { echo "USAGE: path_cleanup <PATH_NAME>"; return 1; }
# Ueberpruefe, ob awk und nawk installiert sind
test -x /bin/nawk || { echo "ERROR: nawk is not installed"; return 1;... (2 Replies)
Hi.
I need a script (either bash or perl) that can delete previous versions of files.
For instance, from our continuous build process I get directories such as
build5_dev_1.21
build5_dev_1.22
build5_dev_1.23
build5_dev_1.24
I need a script that I can run every night (using "at"... (6 Replies)
Hi!!,
my HP-UX - 10.2 compiler doesnt appear to support ANSI style of coding. On compiling my C code, it flags error messages like
error 1705: Function prototypes are an ANSI Feature
Is it a generic problem with the HP compiler or do I need to use some special switches on the command... (9 Replies)