HI all,
could please help me in this code. I have 560 files containing the same columns but different rows. i want to concatenate all these files in one big file. i want to keep the header of the first file then add the dat from other files horizontally.
the name of my files contains 2 variables : chunk number and chromosome number. this an example
code:
IMP_chunk11-chr6_file
i have tried this code but it works only for one variable and 22 files. anu suggestion to adapt it to my case
code :
thank you veru much
Moderator's Comments:
edit by bakunin: Please reread the rules, CODE-tags are not optional when posting code. Thank you.
You didn't tell us if there is any naming convention on the file names, so it is difficult to suggest a loop where you don't have to name the possible file names but instead generate them. In any case the loop you use should NOT be a for-loop, because it can break if a file glob expands to something you didn't foresee.
Instead, use a while-loop, like this:
To add a file to another without the first two lines you can use "sed":
So, putting it together, your script could look like this - you will have to supply the correct file glob instead of "*input", which i used for demonstration purposes:
This will copy the first input-file (preserving the 2-line header) and cut off the header of any following file. "if [ -e <filename> ]" means: if "<filename>" exists and is a regular file. Because any eventually existing output file is deleted prior to the loop this is not the case with the first file.
thanks so much Bakunin for your help,
i created a filelist with all the names for the files that i want to concatenate. as you can see attached in "files_name" the names of these files is doest fellow a rules.
how can you script be adjusted to this please
thanks again
p=2
k=0
cat file1 >>EUR.all.Fst
while read file
do
while read line
do
if [ k -eq 1 ]
then echo "$line" >>EUR.all.fst
fi
k=1
done <$file
k=0
done <file.list
If you already have the list in a file, just "cat" it into the loop. The loop just takes one file name in every run, so as long as you provide this one filename all is fine. "ls" would have provided such a list of file names and "cat /path/to/yourlist" can too. Therefore replace:
Code:
# ls *input | while read infile ; do
cat /path/to/your/file | while read infile ; do
This will do the trick, just modify the script above.
- Concatenate files and delete source files. Also have to add a comment.
- I need to concatenate 3 files which have the same characters in the beginning and have to remove those files and add a comment and the end.
Example:
cat REJ_FILE_ABC.txt REJ_FILE_XYZ.txt REJ_FILE_PQR.txt >... (0 Replies)
Hi
I am trying to learn linux step by step an i am wondering
can i use cat command for concatenate files but i want to place context of file1 to a specific position in file2 place of file 2 and not at the end as it dose on default?
Thank you. (3 Replies)
Hi All,
Need your help.
I will need to concatenate around 100 files but each end of the file I will need to insert my name DIRT1228 on each of the file and before the next file is added and arrived with just one file for all the 100files.
Appreciate your time.
Dirt (6 Replies)
Hey!
I wanted to find a text version of the Bible for purposes of grepping. The only files I could find, (in the translation I wanted), were Old Testament.txt and New Testament.txt. I thought, "fine, I'll just concatenate those two, no problemo." But when I unpacked them, turns out they had each... (22 Replies)
I have a file named "file1" which has the following data
10000
20000
30000
And I have a file named "file2" which has the following data
ABC
DEF
XYZ
My output should be
10000ABC
20000DEF (3 Replies)
Hi, I want to create a batch(bash) file to combine 23 files together. These files have the same extension. I want the final file is save to a given folder. Once it is done it will delete the 23 files.
Thanks for help. Need script. (6 Replies)
I have directory structure sales_only under which i have multiple directories for each dealer
example:
../../../Sales_Only/xxx_Dealer
../../../Sales_Only/yyy_Dealer
../../../Sales_Only/zzz_Dealer
Every day i have one file produce under each directory when the process runs.
The requirement... (3 Replies)
need a shell which perform following function
file 1 ( every time new data comes)
1212
2323
3434
4545
5656
.
.
.
.
file 2 (fixed line)
update bc_tbl set aix=data , bix=back where cix=U and serial=;
now when i execute shell it will concatinate file 1, file 2 & make file 3 as... (3 Replies)
Hi, I'm totally new to Unix. I'm an MVS mainframer but ran into a situation where a Unix server I have available will help me. I want to be able to remotely connect to another server using FTP, login and MGET all files from it's root or home directory, logout, then login as a different user and do... (1 Reply)