General :: Select Lines From FileA Based On A Key Field In FileB

Feb 11, 2011

I want to select lines from FileA based on a key field in FileB.

egrep does this nicely:
"egrep -w '0132874|0132880|0100765' < " FileA

Suppose FileB consists of three lines:

0132874
0132880
0100765

Is there a way to code egrep to do the selection? I really like code which does not use explicit loops so my interest is to find a grep or egrep or sed (or some other) command to perform this function.

Neither file is sorted on the key field but they could be. There is no requirement to keep the files in their present order.We may assume that each key value in each file is unique.

View 2 Replies


ADVERTISEMENT

General :: Grep To Select Lines With M In Last Word

Mar 6, 2011

I have a large file in which each line has three or more blank-delimited words. I'd like to code a grep to keep only those lines which have the letter M in the last word. the M (if present) will be the first character in the last word.

View 14 Replies View Related

General :: Field-terminating Char Appears Within Field Values?

May 18, 2010

I've had a very colorful morning learning the innerparts of Linux's sort command, and have come across yet another issue that I can't seem to find an answer for in the documentation. I'm currently using -t, to indicate that my fields are split by the comma character, but I'm finding that in some of my files, the comma is used (between double-quotes) within values:

Jonathan Sampson,,foo@bar.com,0987654321
"Foobar CEO,","CEO,",ceo@foobar.com,,

How can I use a comma to terminate my fields, but ignore the occurences of it within values? Is this fairly simple, or do I need to re-export all of my data using a more-foreign field-terminator? (Unfortunately, I do not have any control over declaring a different terminator with this particular project).

View 2 Replies View Related

Programming :: Equivalence Classes Based On Field Values And Multi-key Hashtable?

May 12, 2010

I've got a set of objects (all of the same type). I'm trying to think of a good way to divide it into equivalence classes, with equivalence of two objects defined as meaning a specified set of attributes are equal for both objects. More concretely, I've got:

- a Java class with around 50 fields
- a bunch of instances of the class

I want:

- to divide the instances into a few sets
- in each set, each instance has field 1 - field 5 equal to fields 1-5 of the other instances in the set.

The method I've come up with is to generate a hashcode for each instance based on the hashcodes of fields 1-5*, and map the hashcode to one of my sets. Ignoring problems with potential hashcode collisions (which I'm expecting to be too rare to worry about for now), does that sound reasonable? It seems simple enough, but I'm wondering if there's a simpler method I haven't thought of.

* I'll generate the hashcode using a method based on Eclipse's generic hashcode method, which looks like this:

Code:

public int hashCode() {
final int prime = 31;
int result = 1;

[code]....

View 5 Replies View Related

Ubuntu :: Select Lines Containing Word And Copy To Another File?

May 31, 2011

I am trying to find a way to search a text file for a certain keyword and then select each line containing the word , copy and paste these lines into another text file. I can do this easily with UltraEdit but I cannot figure out how to do it in Jedit or Scite.

View 5 Replies View Related

Programming :: Select The Branch Based On The INPUT?

May 23, 2011

I want to select the branch based on the INPUT. Here is the program segment which uses the case statement.

case $INPUT in

1)branch="Computer Science";;
2)branch ="Electrical";;
3)branch = "Mechanical";;
4)branch= "Aerospace";;
esac

When I run this script, I am getting an error, Electrical command not found?

View 2 Replies View Related

Programming :: Remove Many Lines Based On Content Of Other File

Jun 21, 2011

I a csv-file (A.csv) with a total of 4.600.000 lines. Thats to many and only a few is necessary. I have a txt-file with 150 lines (X.txt) (all lines is dataset from a mainframe and looks like abc.def.123.456. How do I remove lines from A.csv where none of the dataset from x.txt is present?

View 13 Replies View Related

Programming :: Awk - Print A Field When Field Position Is Unknown ?

Mar 28, 2010

I'm trying to display fields from flat files where the first 8 fields are always the same. Fields 9 - n are varied but will contain specific patterns I'm after. I'm using this so far because "mySearch" is on each line I want to examine.

Code:

How would you pattern match and include 2 additional fields above field $9 but change field position from line to line?

View 12 Replies View Related

Programming :: Awk Printing From Nth Field To Last Field

Jan 8, 2010

How can print the, let's say 5nd field to the last field of every record (let's say we have 10 fields)?

I mean: I cant avoid to have to do:

print '{$5 $6 $7 $8 $9 $10}'

View 2 Replies View Related

Programming :: Php - Get A Return From A Field Within A Field?

Apr 27, 2009

I am creating a game with random variables. In the game I have created a dialogue exchange to players. I have set up a table with various returns and I inserted {$fields} to represent various random variables. When I call on the requested fields, I only see the field text and my field names. Am I supposed to parse something and call it back another way?

ie: myfield is: "You have won {$random1} silver! <br />{$wi['gender'] majesty rewards you well." the code I am using to call that field is:

View 11 Replies View Related

General :: Delete All Lines Containing A String, Plus 4 Lines Below It?

Jan 26, 2010

I've come across an unusual requirement for a service in my Ubuntu system.Simply put, I need to find a way to search for all instances of a term in a file, delete lines containing containing that term, and delete four lines below each instance of that term. ither that, or copy the entirety of a file to a new file and skip over all lines containing the term plus four below it.This sounds kinda weird, I know. Without going too far into detail, I either have to change the logfile format for a server I'm running which is a huge pain in the butt, or I can just run a script to edit an HTML report generated from said logs. (Said report is really just for managers to peruse, and I like my log format, so I'm pursuing option 2.)

View 4 Replies View Related

General :: Debian Based - Arch Based - What Is The Practical Difference?

Jun 7, 2010

I notice that on DistroWatch, the descriptions include "debian based", "arch based", etc. For the newbie, is there any practical difference between the different bases, or is it a Coke vs Pepsi type question?

Is a distro based on Debian say, easier for a newbie to learn or work with than say one that is FreeBSD based?

View 9 Replies View Related

Programming :: Get A Field Value Corresponding To Another Field Value?

Dec 14, 2010

i have a file : file.dat with following data

Code:

STORAGE PERCENTAGE FLAG:

/storage_01 64% 0
/storage_02 17% 1
/storage_03 10% 0
/storage_04 50% 1

I need to get the value of PERCENTAGE in a variable for a value of storage passed as variable i have tried the following without success like :

Code:

percentage='awk -vx="$defaultStorage" '{FS=OFS=" "}$1==x{print $2}1' file.dat

View 2 Replies View Related

General :: Frame Based Vs Dialog Based

Apr 5, 2010

When you use an IDE and it asks you if you want frame based or dialog based, what is the difference?

View 1 Replies View Related

General :: Distro Should Use, Rpm Based Or Debian Based?

Feb 2, 2011

what distro should i use, rpm based or debian based?

View 2 Replies View Related

General :: Keep Last 'n' Characters Of A Specified Field?

Apr 4, 2010

The input file consists of several fields. The first field is always five or more characters long. I want to keep the last five characters of the first field.

Example:
If the input file record is FEDERAL PACIFIC ELECTRIC PRODUCTS then I want to keep DERAL I can do this in four steps by using C, REV, C, and REV again but that seems like doing an easy thing the hard way. Is there a straightforward way to achieve this result with C or some other command?

View 14 Replies View Related

General :: Is Field BusID Necessary In XF86Config?

Mar 1, 2011

I am using a cluster of machines running on Ubuntu 10.04 LTS which are supposed to be homogeneous, but apparently they are not. In particular, I am configuring the X server on these machines.The problem is that the BusID of the graphic card is PCI:5:0:0 for some machines, and PCI:3:0:0 for others. Is there a way that the X server automatically detects the appropriate Device (based on the name for instance)?

View 1 Replies View Related

General :: Add Second Field Of Two Files On Different Servers?

Sep 1, 2010

I have one file placed at one server whose sample as follows:

57272 28
56767 0
57575 4

[code]...

View 13 Replies View Related

General :: Merge 2 Files With AWK By The Field Value

Jun 1, 2010

i have 2 file and want to merge them in the first one. the first file is like this:

2 word1
1 word2
6 word3
2 word4
......

the second:

word1 :file1 :file2
word2 :file6
word3 :file1 :file2 :file2 :..up to file6
word4 :file7 :file1
.......

So i want to ADD all those File fiels Wich have different FN for every record.

View 8 Replies View Related

General :: Replicate A Specific Field?

Apr 24, 2010

I have a file containing text. I want to replicate a specific field.For example, I might want to append a copy of the second word of each line to the end of that line.Have: Once upon a midnight dreary, while I pondered weak and weary,Over many a quaint and curious volume of forgotten lore, Want: Once upon a midnight dreary, while I pondered weak and weary, upon Over many a quaint and curious volume of forgotten lore, many Is there a Linux command which will do this? I seek a basic command, not awk, not Perl, because I haven't learned those things yet.

View 14 Replies View Related

General :: Set GECOS Field For Existing User?

Sep 27, 2010

I would like to know the command to change or add GECOS field of existing user. when i tried to find the command i end up getting this which is only valid for new user account.

Code:

useradd --help
-c, --comment COMMENT set the GECOS field for the new user account
My system details.

Code:

# lsb_release -a
LSB Version: :core-3.1-ia32:core-3.1-noarch:graphics-3.1-ia32:graphics-3.1-noarch
Distributor ID: OracleVMserver
Description: Oracle VM server release 2.2.0
Release: 2.2.0
Codename: n/a

View 1 Replies View Related

General :: Send Mail If All Values In Second Field Are Zero?

Sep 1, 2010

In my file there are 2 fields separated by space.Sample content of file are as follows:56060 154242 053030 0Now i want to check second field of the file and if all values in second field are 0(zero) and send mail containing all contents of the file

View 3 Replies View Related

Programming :: Remove Lines In A Text File Based On Another Text File?

Jan 28, 2009

I have a text file called file1.txt containing many lines eg.

line1
line2
line3
line4
line5
line6

Then i have another text file called file2.txt contains

3
5
6

Is there a command to remove the lines in file1.txt based on the keywords in file2.txt? note: It should remove line3,line5,line6 based on 3,5,6

View 10 Replies View Related

General :: Bash Script Is Reprinting Part Of A Field From An Awk Statement?

Apr 21, 2010

Here's the bash script:

Code:

FILES="/usr/sbin/accept
/usr/sbin/pwck
/usr/sbin/chroot
/usr/bin/fakefile

[code]....

Notice the extra" file size" lines in there? What's causing that? I'm trying to learn more bash skills. I have no experience with awk because I have been unable to understand it's basic necessity. But I thought maybe if I try it with some test scripts I might become more interested in using it more and expand my very limited capabilities.

View 13 Replies View Related

General :: Search A File To Find If Variable Belongs To A Field?

May 18, 2011

I have a file that contains 5 fields and anothen one with two I want to take the value from user and search file1 and if the value exists then write in file2 to the $2 to the line that $1=value

file 1
1:fsdfsd:g:33:fsdf
2:yytgdcf:a:3:sgd
3:tttt:g:67:yujhggfg

[code].....

View 2 Replies View Related

General :: Removing Specific Field Seperator To Combine Two Fields?

Dec 2, 2010

I am trying to remove the space between the 2nd and 3rd fields but just cannot work out how to do it. I've considered sed, cut, awk...I know with sed you can replace all instances within a file but can you also specify to remove, say, the 2nd instance of a space in each line (this would be perfect for me)?

DAAE 60 402 Bejaia Algeria 1 36-43N 005-04E 36-43N 005-04E 2 2 P
DAAG 60 390 Dar-El-Beida Algeria 1 36-43N 003-15E 36-43N 003-15E 25 25 P
DAAJ 60 670 Djanet Algeria 1 24-33N 009-28E 24-33N 009-28E 1054 1054 P

[code]...

View 3 Replies View Related

OpenSUSE :: Web - Screen Loads And After Initial First Few Lines Breaks Up Into Multiple Repetitions Of Lines

Apr 22, 2011

I have been experiencing a problem where the screen loads and after initial first few lines breaks up into multiple repetitions of lines. Reloading helps but has to be repeated when pageing down. Mail is no problem; it is supplied by my network provider. OS is openSUSE 11.2 which I update when advised. Below is a sample from the error console:

[Code]...

View 1 Replies View Related

Ubuntu :: Wobbly Windows Lines - Get These Lines When Drag/move The Window Upwards

May 31, 2011

I've just installed Kubuntu 11.04, switched on wobbly windows effect. It runs very smooth on my Nvidia GeForce 7600 GS with dual screen twinview turned on. However, I get these lines when I drag/move the window upwards - see screenshot:

View 6 Replies View Related

Programming :: Remove Lines And Parts Of Lines From Python Strings?

Nov 24, 2009

How do you remove parts of strings using python? Such as, if I have something like:

Code:
erme1 sdifskenklsd
erme2 sdfjksliel

[code]....

View 3 Replies View Related

General :: Replace Several Lines In A File With Other Lines In Another File?

Oct 26, 2009

I have this massive table file with some data in it and I want to replace some lines that are wrong with the correct ones that are in another table file of the same format. The wrong lines are not all together in a block but randomly distributed so I need to make a loop checking if the line is in the other file and if it is, replace it. I want to try and do it with sed or awk but I don't really know how to....

View 12 Replies View Related







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