LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   shell scripting.. where to start? (https://www.linuxquestions.org/questions/linux-software-2/shell-scripting-where-to-start-144478/)

f0rmula 02-10-2004 11:45 AM

shell scripting.. where to start?
 
never written a script before, but now im finding the need for them...

here goes..

i want to write a shell script to take interleave the lines of a file with another..

i.e.

---------------------

file1.txt:

1
2
3

-------------------

file2.txt

10
11
12

--------------------

to produce another file..

1
10
11
12
2
10
11
12
3
10
11
12

-----------------------

where would i start on how to learn to do this, or has anyone got a simple solution or idea that might help

thanks in advance :)

james

mfeat 02-10-2004 11:53 AM

cat file1 | while read a; do echo $a; cat file2 | while read b; do echo $b; done; done

lone_nut 02-10-2004 12:24 PM

Or save a loop and simply type:
cat file1 | while read a; do echo $a;cat file2;done

Happy hacking

f0rmula 02-11-2004 04:39 AM

blinding.. thankyou :)

ill have a go and let you know..

james

f0rmula 02-11-2004 05:16 AM

first one works beutifully, second one leave the lines from the first file, tagged onto the ends of the lines of the second file..

is there any way i can insert characters into the sequence? i.e. insert tabs before the lines of the second file to lay them out tree style.. :)

james

mfeat 02-11-2004 09:24 AM

Or save a loop and simply type:
cat file1 | while read a; do echo $a;cat file2;done"

that's even better!
_____________________________

"first one works beutifully, second one leave the lines from the first file, tagged onto the ends of the lines of the second file.."

second one should work also, sounds like you don't have a newline at the end of the second file
_____________________________

"is there any way i can insert characters into the sequence? i.e. insert tabs before the lines of the second file to lay them out tree style.."

cat file1 | while read a; do echo $a; cat file2 | sed 's/^/\t/'; done


All times are GMT -5. The time now is 02:58 PM.