Modification of Two Files


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Modification of Two Files
# 1  
Old 01-22-2011
Modification of Two Files

I have a script that produces two output files each containing the same number of lines <file1.txt> and <file2.txt>. What I need to do is combine both files into a new file <file3.txt> where line 1 of <file1.txt> is put to the right (and on the same line) as line 1 of <file2.txt> and then the same for the rest of the lines.

Then I need to add a comma to the end of every line EXCEPT the last line which needs a closing bracket.

Any advice / help would be appreciated.

Thanks

./pjg
# 2  
Old 01-22-2011
look into 'man paste'
# 3  
Old 01-23-2011
PHP Code:
paste file1 file2 sed 's/$/,/g' sed '$s/,$/}/' 
- paste the files with lines next to eachother
- put , at end of every line
- replace the , at end of last line with }

Then just redirect output with > file3

I hope that should be good.
# 4  
Old 01-23-2011
Many thanks for both replies. If I wanted to seperate file1 and file2 with a | sign do I need to have this in file1 or file2 already or can it be added as part of the paste?
# 5  
Old 01-23-2011
look into 'man paste'

-d, --delimiters=LIST
reuse characters from LIST instead of TABs
# 6  
Old 01-24-2011
Thanks everyone for their help so far. I almost there but one thing has been causing me issues all day....

Code:
paste $prog $pan | sed "s/^/\'/" | sed 's/$/',/g' | sed '$s/,$/') with ur;/' > $progpan

The above is giving me 99% what I need. The only extra is getting a single quote mark ' to appear where I've marked in red.

Whatever I have tried with double quotes or backslashes has created a variety of errors.

Thanks

./PJG

---------- Post updated at 06:08 PM ---------- Previous update was at 06:03 PM ----------

Code:
paste $prog $pan | sed "s/^/\'/" | sed "s/$/\',/g" | sed '$s/,$/) with ur;/' > $progpan

I've cracked it!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sort and move multiple files by modification date

Hi I have a problem, I have a large group of archive files in a folder some are later versions of the same archive, the only difference btween them is that the archiving program we use appends the name with a code for it to keep track of in its data base, and the modification date. I am starting... (6 Replies)
Discussion started by: Paul Walker
6 Replies

2. Shell Programming and Scripting

Modification of MySQLDump-files before compression needed

Hi @all! In my MySQL-backup-script I backup and compress every single table with this command: /usr/bin/mysqldump --opt database_x table_y | /usr/bin/pbzip2 -c > "/media/BackUpDrive/Backup/table_x.gz"Unfortunately these files need modification - they have to start with the following line(s):... (7 Replies)
Discussion started by: gogo555
7 Replies

3. Shell Programming and Scripting

Ls ignoring files from their modification time

Hi everyone, I'd like to know if is there a way to list files but ignoring some according to their modification time (or creation, access time, etc.) with the command 'ls' alone. I know the option -I exist, but it seems to only looking in the file name.. Thank you in advance for the... (8 Replies)
Discussion started by: Keyhaku
8 Replies

4. Shell Programming and Scripting

Compare the files in 2 different servers for change or modification

I have the following requirement; I need to compare set of files in 2 different servers A and B. Both have same sets of files and directory structure First I need to move the files from Server A to server B Compare the corresponding file in B server and see if it has modified (not... (1 Reply)
Discussion started by: vskr72
1 Replies

5. Shell Programming and Scripting

Rename old files with last modification date

Hi everyone, I have files like file1_Mod.txt, file2_Mod.txt. I want to rename the old files with the last modification date. I write the below script to rename with current date, but I don´t know how to use "date -r" to get the last modification date with the same format I have below... (5 Replies)
Discussion started by: cgkmal
5 Replies

6. UNIX for Advanced & Expert Users

Help with sorting files according to modification date

Hi, I was very surprised to not be able to find an answer to this question despite my best efforts in Google and elsewhere. Maybe it's a good thing as it forced me to finally become a member in this great forum that i use frequently. Ok my question: I want to be able to sort files inside a... (3 Replies)
Discussion started by: stavros
3 Replies

7. Shell Programming and Scripting

List the file or files with last modification date

hi. I need help my programing friends :p I need to list all the files with a certain name (for example FileName) by last modification date but only the one with the last date. If there are two files with the same name and same modification date it should print the both. For example in this set... (6 Replies)
Discussion started by: KitFisto
6 Replies

8. Shell Programming and Scripting

Archive Files over certain modification time

Environment is cygwin on Windows Server 2003 as I could not think how I would achieve this using Windows tools. What I want ot achieve is the following. I have a Directory D:\Data which contains further subfolders and files. I need to move "files" older than 6 months modification time to... (4 Replies)
Discussion started by: jelloir
4 Replies

9. Shell Programming and Scripting

Copy files based on modification date

How to copy files from a location to a directory <YYMM> based on last modification date? This will need to run daily. I want to copy those file for May to 0905 and Jun to 0906. Appreciate your guidance.:) Thanks. -rw-rw-rw- 1 ttusr tgrp 4514 May 29 21:49 AB24279J.lot_a... (17 Replies)
Discussion started by: KhawHL
17 Replies

10. UNIX for Dummies Questions & Answers

Last modification times of files less than 6 months old

How do I get the modification time for files less than 6 months old? (It seems for fles as old or older than this I get to see only the day,month and year. I tried the option -u but it gives me the last accessed time) (1 Reply)
Discussion started by: Abhishek Ghose
1 Replies
Login or Register to Ask a Question