Shell Scripting

I'm trying to write a unix script to handle this function
we are in the ksh env, but force bash in scripting
I have three files as input and need to concatenate them onto one line at a time

For example: The first record of each file is
File 1 =a
File 2 =b
File 3 =c

Output should be a;b;c

Second line of each file is

File 1 =d
File 2 =e
File 3 =f

output should be d;e;f

I would like to eventually open this file in excel. That is why I added the delimiters.

awk -F= '{ORS=NR%3?";":"RS"}' file > file.csv

not familiar with awk

can you tell me what this is doing or how do I represent my files

cut -f2 -d"=" sample.txt | tr "\n" ";"

cut command gives the secong coloumn with delimiter "="

tr -- translates the \n to ;

Sorry I forgot to print the values:

awk -F= '{ORS=NR%3?";":RS}{print $2}' file > file.csv

I think I've misrepresented my input files. I have three files with data in them. I want to string the data in those files together on one line, so I tried a cat statement, but it just lists all the files end to end. I need unix to read one record from each file and string them together on one line with delimeters, then go to the next line on each input file and create a new line on the output file with second record. Each file has approx 10,000 lines on it. All the reconstructed records need to be on one output file in a csv format
sorry for the confusion or maybe I'm just confused on what you guys are showing me

awk '{getline a < "file2";getline b < "file3";print $0,a,b}' OFS=";" file1 > file.csv

I just replaced your file names with my actual names and got some errors.

awk '{getline a < "scomp2p8_2010_03_01.txt";getline b < "scomp2p6_2010_03_01.txt";print $0,a,b}' OFS=";" scomp2p5_2010_03_01.txt > scomp2p9_2010_03_01.txt''

awk: syntax error near line 1
awk: illegal statement near line 1
awk: syntax error near line 1
awk: illegal statement near line 1

---------- Post updated at 03:36 PM ---------- Previous update was at 03:34 PM ----------

[/COLOR]that double quote at the end isn't actually part of the awk statement

Try nawk or /usr/xpg4/bin/awk on Solaris.

I got it to work with nawk thanks, but for some reason when I replace the hardcoded file names with variables. It won't accept RUNDATE variable.

RUNDATE="2010_03_24";

nawk '{getline a < "scomp2p8_${RUNDATE}.txt";getline b < "scomp2p6_${RUNDATE}.txt";print $0,a,b}' OFS=";" scomp2p5_${RUNDATE}.txt > scomp2p9_2010_03_24.txt

Also the usr/xpg4/bin/awk seems to exist on the box, but this statement won't work. Just curious why?

usr/xpg4/bin/awk '{getline a < "scomp2p8_2010_03_01.txt";getline b < "scomp2p6_2010_03_01.txt";print $0,a,b}' OFS=";" scomp2p5_2010_03_01.txt > scomp2p9_2010_03_01.txt

bash: usr/xpg4/bin/awk: No such file or directory

thanks for all the help

With shell variables the command should be:

nawk -v rd=${RUNDATE} '{getline a < "scomp2p8_"rd".txt";getline b < "scomp2p6_"rd".txt";print $0,a,b}' OFS=";" scomp2p5_${RUNDATE}.txt > scomp2p9_2010_03_24.txt

You forgot the slash before usr.

... deleted ... redundant solution...

still doesn't recognize the rd variable. doesn't read in the files within the double quotes.

nawk -v f1="scomp2p8_"${RUNDATE}".txt" -v f2="scomp2p6_"$(RUNDATE)".txt" '{getline a < f1;getline b < f2;print $0,a,b}' OFS=";" scomp2p5_${RUNDATE}.txt > scomp2p9_2010_03_24.txt

Thanks that worked. I don't know who came up with this idea of sharing the knowledge, but I love it.

Thanks big time

Hopefully sometime I can return the favor