Removing part of a file name and appending into a single file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing part of a file name and appending into a single file
# 1  
Old 05-04-2012
Removing part of a file name and appending into a single file

I have two files like ABC_DEF_yyyyymmdd_hhmiss_XXX.txt and ABC_DEF_yyyyymmdd_hhmiss_YYY.txt. The date part is going to be changing everytime. How do i remove this date part of the file and create a single file like ABC_DEF_XXX.txt.
# 2  
Old 05-04-2012
do you want to merge data from these type of files into one file ABC_DEF_XXX.txt?
# 3  
Old 05-04-2012
I don't know what you are trying to accomplish exactly. Are you wanting to retain the contents of the file or just create new one without date?

Here ya go:

Code:
cat ABC_DEF_yyyyymmdd_hhmiss_XXX.txt > ABC_DEF.txt

Or....
Code:
mv ABC_DEF_yyyyymmdd_hhmiss_XXX.txt ABC_DEF.txt

Or....

Give some specifics, and I'm sure we can help you out!

---------- Post updated at 02:35 PM ---------- Previous update was at 02:32 PM ----------

If it is in a script that is reading this, maybe put this in:

Code:
sed -e -i 's/ABC_DEF.*$/ABC_DEF.txt/g' ABC_DEF_yyyyymmdd_hhmiss_XXX.txt

# 4  
Old 05-04-2012
Okie.. i want to remove the dynamic date part of both the files and merge it to a single file abc_def_xxx.txt.

To be specific, this is being used in a shell script that will pass the initial name of the file ( say abc_def.txt). Now my search directory woud be having some files with the pattern, abc_def_yyyymmdd_hhmiss_XXX.txt . So i need to search the directory for this pattern. once the files are found in the target directory, i need to merge thses files into a single file which will be named as abc_def_xxx.txt.

Hope i am clear this time. Please suggest how to get this accomplished
# 5  
Old 05-04-2012
Assuming you already have list of files needed to be merged. Following is one method you can follow:
Code:
>abc_def_xxx.txt
while read file
do
cat $file >> abc_def_xxx.txt
done < file_list

# 6  
Old 05-04-2012
This is just a sample. I am sure you can modify it to fit your needs:

Code:
#!/bin/sh
filemerge=/path/merge
newfile=/path/abc_def_xxx.txt.
#
ls /path/directory/ | grep abc_def* > $filemerge
#
for j in `cat $filemerge`
do
cat $j >> $newfile
echo "adding $filemerge to $newfile"
done
rm $filemerge

# 7  
Old 05-04-2012
How do i extract the date part of the existing file in the process to use it in the log flog_<date part extracted>. Also i want ot remove the original files after the merge
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Removing duplicates on a single "column" (delimited file)

Hello ! I'm quite new to linux but haven't found a script to do this task, unfortunately my knowledge is quite limited on shellscripts... Could you guys help me removing the duplicate lines of a file, based only on a single "column"? For example: M202034357;01/2008;J30RJ021;Ciclo 01... (4 Replies)
Discussion started by: Rufinofr
4 Replies

2. Shell Programming and Scripting

Shell script - Replace just part of a single line in a file.....

Hey guy's.... I new here, But im working on a school project, and I am not really good at programming. In fact, this is the only programming class that I need because programming is not what I am majoring in. But I have everything done in this shell script except for this last part..... ... (9 Replies)
Discussion started by: hxdrummerxc
9 Replies

3. Shell Programming and Scripting

removing part of a file

Right this is quite a long one, I have a script which complies all listed stats files into one file and emails it out, However this has to be run manually and i would like it to run automatically, I have a list of files eg sa17 sa18 sa19 sa20 sa21 one file for each of last weeks... (9 Replies)
Discussion started by: Bdoydie
9 Replies

4. Shell Programming and Scripting

Removing duplicate records in a file based on single column explanation

I was reading this thread. It looks like a simpler way to say this is to only keep uniq lines based on field or column 1. https://www.unix.com/shell-programming-scripting/165717-removing-duplicate-records-file-based-single-column.html Can someone explain this command please? How are there no... (5 Replies)
Discussion started by: cokedude
5 Replies

5. Shell Programming and Scripting

Removing duplicate records in a file based on single column

Hi, I want to remove duplicate records including the first line based on column1. For example inputfile(filer.txt): ------------- 1,3000,5000 1,4000,6000 2,4000,600 2,5000,700 3,60000,4000 4,7000,7777 5,999,8888 expected output: ---------------- 3,60000,4000 4,7000,7777... (5 Replies)
Discussion started by: G.K.K
5 Replies

6. UNIX for Dummies Questions & Answers

appending in a single text file

actually, i have to grep the value of cpu usage from six differrent servers and it has to generated in a single report( in a single text or excel file). i have used the below command for grepping the value. top -n 1 > arun.txt cat arun.txt | grep 'init' | cut -c 49-53 > output1.csv like... (2 Replies)
Discussion started by: arunmanas
2 Replies

7. Shell Programming and Scripting

rename file by removing some part of the file name

I am special requirements to rename file. I have files with names like below: 1_firstname1_lastname1.html 2_firstname2_lastname2.html 3_fistname3_lastname2.html I would like these file to be renamed as below firstname1_lastname1.html firstname2_lastname2.html... (5 Replies)
Discussion started by: McLan
5 Replies

8. UNIX for Dummies Questions & Answers

Need advice! Removing multiple entries in a single file!

Hello, I have a file Test.txt with 9 columns that looks like this: 1g12 A 14 19 2OAY A 326 331 AAAASA 1l7v A 68 73 1l7v A 68 73 AALAIS 1l7v A 68 73 1XVW B 72 77 AALAIS 1l7v A 68 73 1XXU A 65 70 AALAIS 1l7v A 68 73 1XXU B 65 70 AALAIS 1l7v A 68 73 1XXU C 65 70 AALAIS 1l7v A 68 73 1XXU D... (4 Replies)
Discussion started by: InfoSeeker
4 Replies

9. UNIX for Dummies Questions & Answers

replace part of single string in a file

hi! i have a file consisting of the following lines: (BTW, = space) . . . 12ME_T1mapping_flip30bshortf 13DCE_whole_brainbshortf 13DCE_3Dbshortf . . . the list of scans starts at 1 and goes on sometimes up to 60 scans. i would like to change only the lines that contain 'whole' to... (2 Replies)
Discussion started by: nixjennings
2 Replies
Login or Register to Ask a Question