Programming :: Keeping The Separate Files In Sync Line By Line?
May 5, 2010
I'm extracting data from a xml file writing it to separate files then combining the results as a csv file.The problem is keeping the separate files in sync line by line.When a grep does not action I would like to put in a blank line or something to keep the lines in order.When the "<title>" is missing as in as in the first"<programme </programme>" that's where I need somethingto write to the file as dummy data to increment the line
I am trying to write a program in C which compares two files and prints the line that is equal.
Here file1.txt has
and file2.txt has
Note: file2.txt consist of only a single string where as file2.txt has multiple lines. Actually im comparing two files with md5sum values.
Here is the code but it compares only first line of files..but it should compare the whole file1..and sorry iam a beginner in C can any1 sujest some modification to this code so that..it can compare file2 with entire file1
I have two txt files containing x and y coordinates: xcoord.txt & ycoord.txt. I need to open them; read them line by line to get each coordinate; then each time I need to update Xs and Ys parameters inside another file called "dc.in" with the grabbed values.
Finally each time I need to run two exe files ( dc_2002 and st_vac) and produce corresponding output for each Xs and Ys ( dc.in is an input file for this exe files)
I have written the following code but it does not work:
I have a script that writes the following type lines to a file. The lines include some html tags. Here is an example:<p>Total = 5</h2></b></center>I want to keep the <p> tag, but remove the ending 3 tags. Sometimes the line can have a 1, 2, or perhaps a 3 digit Total. So I could have a Total = 125.Anyway, after the removal of the ending tags the result would be:<p>Total = 5There are some lines in the file that end with </h2></b></center> that I want to keep. These lines looks generally like this:
<p><b><center><h2>Events Summary for Sun May 02 2010</h2></center></b>
As you can see I am using sed to change the beginning and end of lines to make a very simple web page.The file actually displays ok in a browser with the extra tags on the end, but it is just sloppy work to have these unneeded tags in the output file.
I'm a bit new to Python programming and hoped that someone might be able to help with a problem I'm having. What I essentially want to do is to combine two text files line for line. I know how to do this in a bash script so to give you a better idea here's the code for that:
This is basically for adding on values to the end of a CSV file that uses ';' as the delimiter. So say file1 said:
And file2 said:
Then running this command would create merged_file1_and_file2 which would be:
The code I'm using at the moment is:
As I'm sure any experienced python programmer will see, this prints out the first line of the file "csvraw" and then all of the lines of "stamps" and then the remainder of "csvraw".
What I'd like to do is something like: (pseudo code, I know it's not python ;-))
Is this possible? I've tried googling and my Python Pocket Reference hasn't been much help. I've looked at pickling but that doesn't seem appropriate.
I have two files, file1.traj and file2.traj. Both these files contain identical data and the data are arranged in same format in them. The first line of both files is a comment.
At line 7843 of both files there is a cartesian coordinate X, Y and Z ( three digits ). And at line 15685 there is another three digits. The number of lines in between two cartesian coordinates are 7841. And there are few hundreds of thousands of lines in a file.
What I need to do is copy the X Y Z coordinate (three digits) from file1.traj at line 7843 and paste into file2.traj at the same line number as in file1.traj. The next line will be 15685 from file1.traj and replace at line 15685 at file2.traj. And I dont want other lines (data) in file2.traj get altered. This sequence shall be going on until the end of the file. Means copy and substitude the selected lines from file1.traj into file2.traj.
I tried to use paste command but I cant do for specified line alone.
Here i showed the data format in the file. I used the line number for clarity purpose.
I have a project due for my Intro to C++ class and we are suppose to generate a file listing that will take an input of a C++ source code with .cpp extension and make a copy of it with a .lst extention that will have a line number preceding each and every line.
At the moment I have a flat file which is being used by a few people. I want a script to remotely change the file, so I can start logging who is doing what.At this point here is one requirement I am trying to develop. We have text blocks who pretty much look like.I hope this is somewhat clear. I try to find $param for the right $workflow and change that. Can you help me to find $$var3 and change that?
Was wondering if any perl guru's could help me with a quick log file adjustment. I have a text file that looks like so (tabs and newlines are revealed so you can see what separates the data):
There are maybe 100 lines of text in this file at any given time. I need to delete all duplicate lines only looking at the first bit of text prior to the first tab. It doesn't matter which one gets deleted as long as there are no two lines that begin with that same text at the beginning before the first tab. So in this example, either the fist line "1234" or the last line "1234" would need to be deleted. I already have code in my script that opens the files - I just need the code to read the text into an array and the part that would find matches based on the above criteria, and make the deletions.
If it would be easier, I can even do a system call and use SED (v4.1.5) and/or AWK (3.1.5) instead.
bash 3.1.17(2) I'm trying do write a shell script which must operate on each line of an ASCII text file. So, all the code must be inside a loop, and inside the loop, the first thing should be to read the next line from the file. I have the bash read command. But it reads from stdin. Any way to make read from a file?
I'm trying to make another file annotation script a little speedier than it has been by the up-until-now proven method of checking the last four characters in a filename before the "dot" (eg .jpg, .psd) against a list of known IPTC categories and Exiv2 command files. It occurred to me that if one script generated a list of files in directory foo, and the same or another script sorted that list by that four-letter tag,then that list could be used(instead of a for/do/done loop on the real files in the folder) by the command-file-matching script to "vomit out" which annotator file would go with file nastynewfile.jpg, f'r'instance. The script I had been using for this task looks like this:
while read 'line'; do sp=$(echo $line) vc=$(echo $sp | cut -d"," -f1) cv=$(echo $sp | cut -d"," -f2)
Where I seem to be stuck is with how to sort the lines in templist, which may be any number of different lengths, from back to front. sort -k looked promising, except it seems only to work the other way round. I thought of invoking a
q=$(expr length $line); echo $q n=$[q-8]; echo $n
kind of thing, but that presented the problems of how to sort by those, how to tell sort where to find them (grep?) and how to "stitch them back in" to the original list, which is what I want to sort in the first place.
I have a perl/python interpreter available on the system so really as long as the script would run on a standard linux build I'll be happy.So I don't know how to program a script that would find the unique key (which if needed, can be easily stripped out and put into a separate file) and then print out the data below it without going into the other lines.
In C, I want to make a program that will take a file and replace it with a file that's nearly the same but with some minor changes. Also, I would like to point out that I'm still fairly much a beginner with C. As for an example of the file, I want to take something like this:
Random Crap More Random Crap Even More Something That Changes XXXXX
I figured the best way to go about doing this was to open the file and a blank file, read the original bit by bit and when it gets to the point that needs to be changed exchange the part that needs to be changed with what it should be changed to, delete the original file, and rename the new one to the correct name. So the first problem I've run into (and I'll probably have more) is that when I'm trying to read stuff from the original file, my program doesn't seem to be finding the original. I'm sure much of my problems will be just from not knowing how to use the C functions so bear with me. Right now I have the following:
Died Here: No such file or directory Segmentation fault
Right now the length of 50 was just a random test length. Pretty much I was just trying to get it to read anything from the file. In the end I'm going to want it to read the entire file bit by bit, but at the moment I can't seem to get it to read anything.
I have two files (not sorted) and need to compare line by line (i.e. first line of file1 to be compared to all the lines of file2 and so as for the rest of file1). Output will be an array of length of file2. Any suggestion in BASH other than a grep inside two read line loops ( which is time consuming for files ~1000s of lines).