Programming :: Adding Line From File1 Into A Line Of Another File Based On Maching IDs

Jan 3, 2011

I wish to add information to one of my files based on matching IDs,

Here is an example

(the id is the 3 colunm)

(the ID is the 2 colunm)

And the output i wish to be

OUTPUT:

So as you can see the ones that do not match are still present, and the ones that do match just have the extra information from file2.txt added to them.

I thought about using join but that only seems to join the ones that match displays thoes only. i would like all the information in the output file.

View 6 Replies


ADVERTISEMENT

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

Programming :: Filter Source Line Based On Results Line In Log Using Awk And Sed

Apr 5, 2011

I have a log file with entries such as;

Where result is 0 or more.

I want to get the list of file names where result count is more than 0 (in other words filter out files names with result 0).

File name and result are in two different lines in log file.

How can i filter file name based on result?

View 5 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

Programming :: Adding Number And String To Each Line In Data File

Apr 10, 2010

I have a very large data file, with 3 numbers in each line, ex. 3 4 5 ; 6 7 8.I want to add two numbers (0 and 1) at the end of every line, and a string at the beginning of the line. Does anyone know a efficient way to do so?

View 7 Replies View Related

Programming :: Programing - Reading File Line By Line Then Char By Char In Each Line

May 29, 2010

I've never programed shell scripting.

Code goes like so:

I simply want to read a file "data.txt" line by line Then char by char and add them into a result var. The file is supossed to always contain numeric values

View 8 Replies View Related

Programming :: Create File Listing In C++ That Will Generate Line Number On Every Line Of Code

Apr 11, 2010

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.

View 12 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 :: 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: 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

Programming :: C - Copy File Line By Line With Some Slight Changes?

Mar 2, 2010

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:

Code:

Random Crap
More Random Crap
Even More
Something That Changes XXXXX

[code]....

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:

Code:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

[code]...

And when I try to run it I get the following:

Code:

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.

View 11 Replies View Related

Programming :: Error During Reading A File Line By Line In C?

Mar 6, 2010

I have a code over there. It reads a line from file and converts contents of it to double.

Code:
/*
* fileRead.c

[code]...

View 2 Replies View Related

Programming :: QTimer To Read A File Line After Line?

Mar 25, 2010

I need a qtimer to trigger reading of a file line by line, I have the code sort of running with the timer trigger but qtimer will just read the first line over and over as it is now.

Here is the code so far:

self.lcdtimer = QTimer()
self.connect(self.pushButton85,SIGNAL("clicked()"),self.update)
self.connect(self.lcdtimer, SIGNAL("timeout()"), self.lcdxyz)

Code:

def lcdxyz(self):
import time
import os

[code]....

View 12 Replies View Related

Programming :: Deleting Line By Line From A File?

Apr 21, 2010

this script returns me :

sed: -e expression #1, char 2: extra characters after command
sed: -e expression #1, char 2: extra characters after command

Code:

#!/bin/bash
while read line
do
sed -i "$line" 'd' test.txt
done < test.txt

View 12 Replies View Related

Programming :: Insert A Line/value After A Particular Line In File With Sed?

Jan 13, 2010

I need to run a command in a shell script to insert a line in a file, after it finds certain line. To add the line 'user = mysql' after the line [mysqld] in file /etc/my.cnf

View 3 Replies View Related

Programming :: How To Read Line By Line In A File In C

Feb 5, 2010

i want to read line by line in a files in C language actually my porblem is i have a one file cotains

if iam using fgets, it is reading each time AT only it does not moving to Ok in that file

View 6 Replies View Related

Programming :: Read File Line By Line?

Mar 23, 2011

so I have a script that creates couple of txt files. First file output is something like below..

cn=test,ou=something,ou=some,o=org
cn=testa,ou=something,ou=some,o=org
cn=testb,ou=something,ou=some,o=org

second file output is something like below..
usera
userb
userc

Quote:

userdn=`ldapsearch -x -h $server -LLL "(objectclass=person)" dn | grep dn: | cut -d" " -f2 > userdn.txt

for i in $(cat userdn.txt);do

ldapsearch -h $server -p 389 -x -D $admid -w $admpwd -s one -b "$userdn" dn | grep dn: | cut -d" " -f2 | cut -d"=" -f2 | cut -d"," -f1 > user.txt

for i $(cat user.txt);do

echo "$userdn"
done
done

when I ran both ldapsearch commands invidually, they work fine. But when I ran script, I got first file correctly but not the second one. It looks like its not reading the first file correctly and not setting the variable ($userdn) value correctly in the second ldapseach command. I want read first file first line and run the second ldapsearch and continues, then read the second line..and so on.

View 3 Replies View Related

General :: Merge File1 At End Of Line File2?

Mar 23, 2010

how I can merge the data from file1(data per line) to the end of line of file2. So what I mean is, I want to add every line from file1 to the end of the corresponding line of file2.

View 2 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

Programming :: Insert Line Using Sed Or Awk At Line Using Line Number As Variable

Jul 25, 2011

I want to insert a line at a particular line number using sed or awk. where line number is not fixed and is in form of variable.

I want to use variable in sed or awk command.I tried something like below, but no luck.

View 7 Replies View Related

Programming :: Add Line To A File ( 3rd Line)?

Apr 6, 2011

going back to my earlier post "Last digit minus ONE", when i get a Ip addresse with minus 1 ($ip), i need to add the new Ip address ($ip) to resolv.conf of that system. so from resolve.conf:

Code:

# /etc/resolv.conf .......
domain mydomain.ca
nameserver 11.21.36.98
nameserver 11.21.37.98

[code]...

tried with sed

Code:

sed 'nameserver $ip/domain/G' -f /etc/resolv.conf

but not able to get it.

View 6 Replies View Related

Ubuntu :: Adding A Line To Sudoers File So That Every User Can Run A Particular Program As Root?

Mar 27, 2010

is it possible to do so? I mean, I want every user to be able to run '/bin/x' for example, as root without entering a password. I know the security risks, but I'm trying this in a risk-free environment which security does not matter very much.

View 2 Replies View Related

Programming :: Set Indent In .emacs To Enable New Line Starts From The Same Position Of Previous Line?

Dec 29, 2010

How can I set indent in .emacs to enable my new line starts from the same position of previous line?

like this;

Hello world <enter>
Second Hello world // "S" starts right under first line's "H"

View 4 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 :: Perl Script To Replace Line After Finding Previous Line

Feb 28, 2011

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?

View 1 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 :: BASH Sort List By End Of Line To X Position In Each Line?

Aug 18, 2010

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:

Code:

while read 'line';
do
sp=$(echo $line)
vc=$(echo $sp | cut -d"," -f1)
cv=$(echo $sp | cut -d"," -f2)

[code]....

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

Code:

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.

View 14 Replies View Related

Programming :: Scripting To Find Line And Print Previous Line To Out

May 21, 2010

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.

View 4 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







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