General :: Match And Combine 2 Text Files Line By Line

Mar 21, 2011

This solution works but is slow with large files. I am looking for a faster solution.

The 2 files contain filenames, one of them has associated data I want to append to the other file's matching filenames

file1:

file2:

I append file2 by matching the unique_filenames and appending them with the tag data and some formatting

appended file2:


Here is the SLOW code

while read inputline.

View 9 Replies


ADVERTISEMENT

Programming :: Perl - Delete Line From Text File With Duplicate Match At Beginning Of Line

Apr 1, 2009

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.

View 7 Replies View Related

Programming :: BASH: Each Line Of Multiple Text Files Gets Added To One Line?

Sep 12, 2010

I currently have 3 files with floating point data that I wish to have in a single file with the format:

Code:

F1 F1 F3 Output
a1 b1 c1 a1 b1 c1
a2 b2 c2 a2 b2 c2
a3 b3 c3 a3 b3 c3
a4 b4 c4 a4 b4 c4

View 3 Replies View Related

Programming :: Open Two Text Files - Read Them Line By Line And Update Parameters Of The 3rd File ?

Oct 18, 2010

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:

View 14 Replies View Related

Programming :: Using Python To Merge Two Text Files Line For Line

Jul 6, 2010

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:

Code:

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:

Code:

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 ;-))

Code:

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.

View 1 Replies View Related

Programming :: Add A Character To The End Of A Line When A Certain Match Text Is Matched?

Nov 5, 2010

Is there any way to add a character to the end of a line when a certain match text is matched. I have a text file where any line that contacts text XYZ a z is placed at the end.

View 1 Replies View Related

Software :: Join 2 Text Files Based On First Number Present In Every Line Of The 2 Text Files?

Jan 22, 2010

I have 2 text files : file1.txt and file2.txt

cat file1.txt

15 this is a sentence containing various words and spaces
34 this is a another sentence containing various words and spaces

cat file2.txt

2 this is sentence1file2
6 this is sentence2file2
54 this is sentence3file2

I would like to join these 2 files. The result should look as follows :

cat joinedfile.txt

2 this is sentence1file2
6 this is sentence2file2
15 this is a sentence containing various words and spaces
34 this is a another sentence containing various words and spaces
54 this is sentence3file2

==> so the joined file must be sorted on the first number. Any ideas how this can be achieved ?

View 4 Replies View Related

General :: SQL Like Group By And Sum For Text Files In Command Line?

May 2, 2010

I have huge text files with two fields, the first is a string the second is an integer. The files are sorted by the first field. What I'd like to get in the output is one line per unique string and the sum of the numbers for the identical strings. Some strings appear only once while other appear multiple times. Given the sample data below, for the string glehnia I'd like to get 10+22=32 in the result. how to do this either with gnuwin32 command line tools or in linux shell?

[Code]...

View 2 Replies View Related

General :: Replacement On More Than One Line In Text Files Using Shell

Nov 25, 2010

How can I replace one instance of a word in a text file with a piece of text that spreads several lines ? I know sed or awk is the way to go but don't know that how I can introduce new paragraphs using these tools

View 1 Replies View Related

Programming :: Compare Two Files Line By Line And Print The Line Which Is Same?

May 30, 2011

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

Quote:

View 9 Replies View Related

Software :: Grep Query To List 1 Line (which Is Fixed) And The Next Line After It (variable Text)

Jan 20, 2011

How can I list the following with grep. I want to extract 2 lines fron a text file The fixed known part if it exists will static text and the text line after it will change.

A sample file
.
.
textline1

[code]....

If the fixed part does Not exist how can I return error code 1

View 3 Replies View Related

Programming :: Bash: Read A Text File Line By Line?

Jul 7, 2011

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?

View 6 Replies View Related

General :: How To Combine Multiple Text Files

Mar 22, 2011

Combine multiple text files into one text file?

View 5 Replies View Related

General :: Compare Two Files Line By Line?

Mar 24, 2010

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).

View 2 Replies View Related

Programming :: Text On A Specific Line At The End Of A Line?

Jul 26, 2010

I'm trying to add text to a file for a specific group of users, I'll need to do examples as I can't think of an easy way of explaining, my file is like this:

Code:

users{
user1
user2

[code]....

At the present my code lists all the available groups, how would I add a user to a specified group? (e.g add "members user3") to the end of group 1 for example. So the code ends up like this

Code:

members user2,user3

View 14 Replies View Related

Red Hat / Fedora :: Remove Particular Line Of Text From All Php Files

Jul 21, 2010

My site was recently hacked and a line of <JAVASCRIPT> was inserted into all my php files. Is there a way to pull just that one line out of all the php files on the server? I was thinking of using a grep -iR <CODE> *.php then piping thru sed

View 1 Replies View Related

General :: Command Line - Use Find To Find Text Files?

Jul 15, 2011

Is there a way to specify to find that I only want text files (and not binary files)? Grep has an option to exclude binary files, so I thought find probably has a similar feature, but I've been unable to find it.

View 2 Replies View Related

Ubuntu :: Line Breaks When Opening Text Files In Windows?

Mar 26, 2010

I have some text files (Just plain text files, not OpenOffice files or anything) and when I try to open them in Windows they are all one line. I think I read somewhere that Linux uses for new lines whereas Windows uses or something... I am using Kate to edit them, and I have a LOT of files to fix so...

View 9 Replies View Related

Ubuntu :: Copy A Line By Number In Text Files On Terminal?

Apr 10, 2010

I got a text file. Now I want to write a line by its number in a bash variable. That is all.

View 1 Replies View Related

OpenSUSE :: Count Lines In Multiple Text Files From Command Line?

Apr 27, 2010

I want to (from the command line) be able to counte lines in a bunch of files of a specific type in a folder and all its sub-folders. How would I do this?

View 1 Replies View Related

Ubuntu :: Command Line - Find And Replace Text Within Multiple Files?

Aug 28, 2010

I'm pretty sure this is doable from the command line, but my CLI skills have degraded a lot since my pre-Y2K admin days. The goal is to search all the files in the directory for a very long string of text and replace it with another string of text. The text being searched for is my Google Adsense code (which will be stripped from my website) and it will be replaced with a placeholder so I can easily tack something else in there in the future.

Seeing how I have that long snip of code on about 100 pages, automating the process would make life easier.
If I was searching for a single word, I can see ways to do this.
If I paste the code I'm searching for into a text file, is there a way to:
find (contents of oldstring.txt) and replace with (contents of newstring.txt)?

View 9 Replies View Related

Programming :: Bash Reading Multiple Files Line By Line?

Mar 8, 2011

I have a set of files containing data that I need to re-arrange into one single property list.

The files that I have look like this:

Code:
# cat uk
<string>10</string>
<string>11</string>
...
<string>29</string>

[Code]....

So the lines in the files match up but I haven't found a way of reading several files line by line.

View 3 Replies View Related

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

here's the data

Code:

<programme channel="15552.dvb.guide" start="20100504200000" stop="20100504204000">
<category>Show / Game Show</category>
</programme>
<programme channel="14498.dvb.guide" start="20100504200000" stop="20100504203000">

[code]....

View 14 Replies View Related

Programming :: Sed - Add A Line After A Match?

Sep 16, 2009

I need to edit the sudo file on lots of machines. I figure the easiest way is to run a for loop to ssh to each box, sed the sudoers file to a new file & copy/move back over the top of the original (and of course, change permissions accordingly)

The problem is, I'm not sure how to add a line after a match with sed.

So if my file looks like:

Code:

I'd like it to add the new sudoer after "other" so the file looks like:

Code:

View 2 Replies View Related

Programming :: Copy And Replacing Specific Line From File1 To File2 Line By Line

Mar 22, 2011

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.

Code:

View 10 Replies View Related

Software :: Tool For Replacing First Match Per Line?

May 4, 2010

I've got a file that I want to convert to a CSV format.

Each line of the file is something like:

term1a term1b [pronunciation] definition
term2a term2b [pronunciation] definition
term3a term3b [pronunciation] definition

To get it into CSV, I just need to perform 3 find and replace operations:

First, replace the first " " (space) with a "," (comma). Next, replace the first " [" (space and right-facing square bracket) with a "," (comma). Finally, replace the first "] " (left-facing square bracket and a space) with a "," (comma).

The reason it must only be the first such occurance, is the definition area contains lots of spaces and square brackets which I'd like to leave left untouched.

View 1 Replies View Related

Programming :: Sed Move To Prev Line If Match

Jan 31, 2010

sed move to prev line if match

file:

desired result:

View 4 Replies View Related

Programming :: Access A File Line By Line, And Check The Length Of Each Line.

Feb 13, 2011

I want to access a file, and check the length of every line.After, i want to check and replace all lines with length over 10 characters, with a message.Does anyone have a clue on that?

View 1 Replies View Related

Ubuntu :: Combine Columns In Text Files?

Feb 15, 2010

I have two files which I would like to combine. Each file has 2 columns.

File 1:
1 a
2 b

[code]...

View 2 Replies View Related

General :: Getting Numbers From A Line Of Text?

May 10, 2010

I'm working with a rather large file of data taking from a tracking program on my phone, and trying to pull only the longitude and latitude from it. Any given line in the data looks more or less like this:

{"lon":-122.3083848,"time":1.273515839496E9,"source":"skyhook","nap":28,"altitude":0,"name":"location","hpe" :29,"bearing":0,"ncell":0,"lat":47.6544453}

I've run it through this command:

grep skyhook log-2010-05-10_18-17-28.json | cut -d"," -f1,10

to get this:

{"lon":-122.30872015,"lat":47.65812201}
{"lon":-122.3076686,"lat":47.6569975}
{"lon":-122.3079161,"lat":47.656395}
{"lon":-122.3096168,"lat":47.656218}
{"lon":-122.3096285,"lat":47.656206}

Which is a lot nicer, but I would prefer not to have to hand remove the non-number characters by hand since there are thousands of data points. what I could do to get it to just be longitude and latitude in 'number number' format?

View 8 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved