Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Merging 3 files together?

Status
Not open for further replies.

jisoo23

Programmer
Jan 27, 2004
192
0
0
US
Hello all,

I'm still learning Unix so please bear with me =) I'm sure there's a simple solution to this....

I have 3 files; file1.txt, file2.txt, file3.txt with one line of text each (respectively):

header_line

line1=variable

line2=variable

What I'm trying to do is combine all three of these text files and their corresponding line into just one file...i.e. final_file.txt with:

header_line
line1=variable
line2=variable

I know that grep will probably be used somewhere in this...any help is appreciated.

Thanks,
Jisoo23
 
cat file?.txt > final_file.txt

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Ok I see, it's some sort of cancatenation function. So I guess I would execute 3 separate instances of it to acheive my desired result? Like this:

cat file1.txt > final_file.txt
cat file2.txt > final_file.txt
cat file3.txt > final_file.txt

Now I assume that this cat function will enter the strings of text on 3 separate lines instead of putting all 3 strings of text together on 1 line?

Thanks,
Jisoo23
 
Did you even try my suggestion as is ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
No, jisoo23, using separate [tt]cat[/tt] commands would be...
Code:
cat file1.txt >  final_file.txt
cat file2.txt >> final_file.txt
cat file3.txt >> final_file.txt
...or you could do this...
Code:
cat file1.txt file3.txt file3.txt > final_file.txt
The last one is what PHV's example actually does once the shell expands the "[tt]?[/tt]" wildcard.

Hope this helps.
 
BTW, I forgot the most useful tip:
man cat

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks for the help, I'll try this out.
 
jisoo23

You've been a member of this forum for over a year and a half. You asked a question and 2 people replied. Therefore I am confused why you didn't take PHV's advice? If you click on his 'title' you will see he has a vast amount of experience - and it seems to me that his solution is perfect. Why did you not so much as answer him?


Kind Regards
Duncan
 
I think jisoo23 didn't understand that he was literally supposed to type
Code:
cat file?.txt > final_file.txt
, once, with the question mark being a wildcard.
 
Also, I think you misunderstood, he did reply...see:
Ok I see, it's some sort of cancatenation function. So I guess I would execute 3 separate instances of it to acheive my desired result?
 
Yes I did reply, I just didn't understand that "?" was a wildcard. I know my way around Unix a bit but mostly from my own stumping around that operating system, so I have quite a few holes in my knowledge.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top