cannibal
07-14-2008, 12:56 AM
hello,
I need your help
I have files
file1.text
file2.text
I want when I run file3.sh
it shows in the screen
first line of file1.txt (space) first line of file2.txt
second line of file1.txt (space) second line of file2.txt
third line of file1.txt (space) third line of file2.txt
forth line of file1.txt (space) forth line of file2.txt
and so on
linux
please help
webcertain
07-14-2008, 05:06 AM
well, what you are looking for is bash scripting help, so you might do better with a thread title including that.
it does sound a bit odd though, what exactly are you trying to do ?
cannibal
07-14-2008, 05:16 AM
I wrote this script
but it's not working with while loop
#!/bin/sh
clear
echo "please enter the first file with full path"
read a
echo "please enter the seconde file with full path"
read b
y=1
while [ $y <= 7 ]
do
z='NR=='$y
echo "[RECORD]" > c
echo "ABC_NAME" \\c >> c
awk 'NR==1' $a >> c
echo "ABC_TEXT" \\c >> c
awk 'NR==1' $b >> c
echo " " >> c
y=2
done
pagebuzz
07-14-2008, 08:37 AM
Here is a simple perl script that will do what you want. Just change the paths to the files and run from the command line.
#!/usr/bin/perl
$count = 0;
$data = "path_to_file_1";
open (DATA, "<$data");
@data = <DATA>;
close DATA;
foreach $line (@data) {
chomp $line;
$count++;
$FILE1{$count} = "$line";
}
$count = 0;
$data = "path_to_file_2";
open (DATA, "<$data");
@data = <DATA>;
close DATA;
foreach $line (@data) {
chomp $line;
$count++;
$FILE2{$count} = "$line";
}
while ($countprint <= $count) {
$countprint++;
print "$FILE1{$countprint} $FILE2{$countprint}\n";
}
exit;
Socrat
07-14-2008, 08:43 AM
I wrote this script
but it's not working with while loop
Aside from the solution pagebuzz gave you. You use round brackets around the clause of a while loop, not square brackets.
cannibal
07-15-2008, 02:19 AM
thanks guys
I found this script, it's doing what I want but how can I remove [RECORD] line in c file at the end !!???
#!/bin/csh
clear
echo "please enter the first file with full path"
read a
echo "please enter the seconde file with full path"
read b
e=`more $a | wc -l`
y=1
echo "[RECORD]" > c
while [ $y -le $e ]
do
z='NR=='$y
echo "ABC_NAME" \\c >> c
awk $z $a >> c
echo "ABC_TEXT" \\c >> c
awk $z $b >> c
echo " " >> c
echo "[RECORD]" >> c
y=`expr $y + 1`
done
zuborg
07-15-2008, 07:59 AM
lam -s ' ' file1.txt file2.txt
zuborg
07-15-2008, 08:22 AM
lam -s ' ' file1.txt file2.txt
Sorry, right answer is
lam file1.txt -s ' ' file2.txt
cannibal
07-15-2008, 02:42 PM
in which line I should add it ?
zuborg
07-16-2008, 06:05 AM
in which line I should add it ?
If you asking about 'lam' command - use it in place where file3.sh could be used.
'lam' just do work of 'file3.sh' - so use 'lam' instead of 'file3.sh' where you need.