Copy(append ) the contents of file1 and file2 to file3
Platform : Oracle linux 6.5
I have two log files with the following contents
I want the contents of myLogfile1.log and myLogfile2.log to be copied(appended) to a single logfile called named mySingleLogfile.log .
How can I do this ?
In this specific case (only the required two files are in the directory)
should do the thing. If there were other files than the two you want to merge, then RavinderSingh13's approach might be the right thing.
I think it could be even abbreviated like this
Up to 9 files cat myLogfile*.log > mySingleLogfile.log should work too, but if you had, say 15 logfiles, e.g. myLogfile1.log myLogfile2.log .. myLogfile15.log, then cat myLogfile*.log > output.log will likely produce wrong output (Wrong order! Compare the output of ls myLogfile*.log and ls myLogfile*.log | sort -V) .... In this case you can try this, provided your sort supports the -V option:
Hope this helps.
This User Gave Thanks to junior-helper For This Post:
cat myLogfile[12].log > mySingleLogfile.log solution suits my requirements.
In my case, the logfile names are assigned to variables first
But, When I am trying to do the equivalent of myLogfile[12].log > mySingleLogfile.log with variables, I am getting the following error because of the [ ] brackets around 123 , I guess
Code:
[root@tblmanh236 test]# cat $LOG[123] > mySingleLogfile.log
cat: [123]: No such file or directory
[root@tblmanh236 test]#
[root@tblmanh236 test]# cat '$LOG[123]' > mySingleLogfile.log
cat: $LOG[123]: No such file or directory
[root@tblmanh236 test]#
[root@tblmanh236 test]#
[root@tblmanh236 test]# cat "$LOG[123]" > mySingleLogfile.log
cat: [123]: No such file or directory
[root@tblmanh236 test]#
## Escaping the brackets didn't work either
[root@tblmanh236 test]# cat $LOG\[123\] > mySingleLogfile.log
cat: [123]: No such file or directory
[root@tblmanh236 test]# cat $LOG[123] > mySingleLogfile.log
cat: [123]: No such file or directory
I am getting the following error because of the [ ] brackets around 123 , I guess
No. Let me explain that: It seems like you exported variables LOG1 LOG2 and LOG3, but here you are "catting" $LOG[123]. Most likely, LOG is not defined at all and hence empty, and only [123] remains and cat cannot find a file with name [123]. The shell treated it like a literal filename [123] because the shell was not able to expand it to something appropriate. [123] alone would match only files with name 12 and 3
Thank You. It is viable. I have multiple log file variables like LOG1 , LOG2, ... declared in my scripts, I guess I will have to change it to what you've suggested If there is no other way
I have multiple log file variables like LOG1 , LOG2, ... declared in my scripts, I guess I will have to change it to what you've suggested If there is no other way
Not sure, I don't know you script and don't know how you want to handle it exactly, but if you wanted to cat files already stored in LOG1 LOG2 and LOG3, (without doing the stunt with LOG I mentioned before), with bash you could try this:
Code:
for i in {1..3}; do
x=LOG$i
cat ${!x} >>mySingleLogfile.log
done
I hope this doesn't complicate the situation further
Quote:
You are not that junior. Are you ?
Edit: Yet another option/variant:
Code:
for i in $LOG1 $LOG2 $LOG3; do
cat $i >>mySingleLogfile.log
done
Last edited by junior-helper; 12-10-2014 at 02:18 PM..
This User Gave Thanks to junior-helper For This Post:
file1
cat
dog
fish
file2
This is a bunch of lines
<!-- INSERT ANIMALS HERE -->
horse
cheetah
post results
file2
This is a bunch of lines
<!-- INSERT ANIMALS HERE -->
cat
dog
fish
horse (1 Reply)
Hi everyone,
I would like to complete the following could you please find some time and help me to achieve below:
File 1 has a list of IP address (more than 1k)
File1:1.1.1.1
2.2.2.2
1.1.1.2
3.3.3.3
2.3.3.2File 2 has content like this:Internet 11.165.91.244 0 Incomplete ... (4 Replies)
Hi
I have two files file1 and file2
File1 10,000 entries:It has 3 columns below.
conn=232257 client=xxx.xxx.xx.xxx:60491 protocol=LDAP
File2 has 500 entries It has two columns.
conn=232257 dn="uid=xxxx,ou=xxxx,ou=xxxx,dc=xxxxx,dc=xxxx"
conn=232398... (10 Replies)
I'm trying to use awk to do the following. I have file1 with many lines, each containing 5 fields describing an individual set. I have file2 which is a template config file with variable space holders to be replaced by the values in file1. I would like to substitute each set of values in file1 with... (6 Replies)
Hi all,
My requirement is that i have two files file1 and file2. file1 content is present in file2. i want to have a final which will have file2 contents but not the contents of file1 so I am running below command.
fgrep -vf file1 file2>file3
no of records in file1 is 65282
no of records... (10 Replies)
I have very limited coding skills but I'm wondering if someone could help me with this. There are many threads about matching strings in two files, but I have no idea how to add a column from one file to another based on a matching string.
I'm looking to match column1 in file1 to the number... (3 Replies)
hi;
my file2.txt:portname=1;list=10.11;l-
portname=2;list=10.12;l-
portname=3;list=10.13;l-
...
my file1.txt:;"{'sector=%27'}"\&>
so; i want to see:portname=1;list=10.11;l-;"{'sector=%27'}"\&>
portname=2;list=10.12;l-;"{'sector=%27'}"\&>
portname=3;list=10.13;l-;"{'sector=%27'}"\&>... (4 Replies)
file1 has pgap500 500
file2 has bunch of data
cat file1 file2 > file3
cp file2 file3.dat then vi pgap500 500 onto 1st line
compare file3 and fil3.dat, they are not the same.
any idea ? the 1st line, i want to put pg500 xxx
---------- Post updated at 07:35 AM ---------- Previous... (2 Replies)
File1 row is same as column 2 in file 2.
Also file 2 will either start with A, B or C.
And 3rd column in file 2 is always F2.
When column 2 of file 2 matches file1 column, print all those rows into a separate file.
Here is an example.
file 1:
100
103
104
108
file 2:
... (6 Replies)
Hi Guru's,
I need to create 3 files with the contents "ABC" using single command.
Iam using:
echo "ABC" > file1.txt file2.txt file3.txt
the above command is not working. pls help me...
With Regards / Ganapati (4 Replies)