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).
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
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?
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;
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:
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?
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)?
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.
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
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.
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
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)?
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.
Is there a way to extract the last field? Specifying the field number is causing problems using awk or cut as the input log file has the output specified in different lines at different places/fields. The only thing constant is the 'pathname' which always occurs at the end.
I want to validate a web form using PHP. I spent ages confusing myself with client side scripting and realised until I worked out it is not what I want. My problem is that now I am looking at PHP and everything is mixed up in my brain. I need to point out that PHP is very new to me! This is what I already have: 1 An html page with my form on it. 2 PHP page which emails the contents of the form to me.
The above works well. For the sake of clarity, here are my pages (cut down to the essentials where appropriate): My html form: first name surname Email Home phone Mobile Work phone
I have read and understood your terms and conditions. My php script (regform.php) $receiver = 'me@email'; $subject = 'New registration'; #$message = 'This is a new registration.'; $surname = $_POST['surname']; $firstname = $_POST['firstname']; $address = $_POST['address']; $email = $_POST['email']; $homeph = $_POST['homeph']; $mobileph = $_POST['mobileph']; $workph = $_POST['workph']; $time = $_POST['time']; #from here $oldaddress = $_POST['oldaddress']; $DOB = $_POST['DOB']; $elect = $_POST['elect']; $job = $_POST['job']; $salary = $_POST['salary']; $employer = $_POST['employer']; $benefit = $_POST['benefit']; $smoke = $_POST['smoke']; $claim = $_POST['claim']; $children = $_POST['children']; $children2 = $_POST['children2']; $pets = $_POST['pets']; $pets2 = $_POST['pets2']; $require = $_POST['require']; $terms = $_POST['terms']; $rooms = $_POST['rooms']; $body = "first name:$firstname surname:$surname DOB:$DOB email:$email home phone:$homeph mobile phone:$mobileph work phone:$workph address: $address time at this address:$time previous address:$oldaddress electoral register:$elect employment:$job employer:$employer salary:$salary benefit claim:$benefit future benefit:$claim children:$children ages:$children2 pets:$pet pet type:$pets2 other requirements:$require terms:$terms"; $headers = 'From: email' . " " . 'Reply-To: email " " . 'X-Mailer: PHP/' . phpversion(); mail($receiver, $subject, $body, $headers, "From: $firstname $surname " . "Reply-To: $firstname $surname class="inlineimg" />;
You can see there are many more form fields than I have shown in my example html form above. What I want is that the following fields have to be filled: 1 mobileph 2 email 3 terms (checkbox) I would like the user to be asked to fill the form in properly if any/all of the 3 fields have not been filled in. I imagine I need some php in the html page and some more in the php page. I am certainly not asking any one to do this for me but I am really confused. I have googled and copied and pasted and edited for 6 hours and I am lost. What I want is a very simple and clear example of the code needed. Sorry if I sound as if I can't search properly on Google: in this case I clearly can't!
how do i ask in a query for any numeric or string field? It may not have any meaning, but i need it to fill a toplink DataReadQuery in java....Something like " select * from table where table.fieldA='?'
I'm using Chromium 10 from the build service and just installed the upgrade to version 10. Now there seems to be an issue with scrolling. When i go to reply to an email in gmail there is something weird when i try to scroll. The scrollbar will move like i am scrolling but nothing actually in the text area moves
I use Ubuntu 10.04 and OpenOffice 3.2.We have forms we use for computers we sell. I have to fill out a profile. The problem is I cannot enter text into the text entry fields. I get this error:"Readonly content cannot be changed. No modifications will be accepted."Here is a link to one of the files. If you try to enter more that a digit or two in a text field, you get that error:[URL]
"Once upon a time", I think heard of a way to use variables in the url field in firefox(or maybe it was ubuntu in general?).Anyways, if one would type, for instance, "google pokemon," the url would be changed to
really only have played around with it off and on. I just installed a new login theme usimg Slim (the Fingerprints theme) and now whenever I restart the virtual machine (using VMware player) it will let me type in my user name but it doesnt show my cursor and wont let me tab down to my password field so I cant get in and change it back to a different theme. Is there any way that I can fix this or will I need to reinstall the whole thing?
An unsuccessful login via a tty by a known user and an unknown user will generate an almost exact line in /var/log/secure with the exception of the last field. To see this specifically do Ctrl-Alt-F2, for example. Now login with a known user and log out. Next attempt a login with a bogus user name which fails. Go back to your GUI enviroment (Ctrl-Alt-F7) and then tail /var/log/secure. For the known user the last field will be "user=some_name_here. The unknown user will not have a "user=" field.
How do I capture the two via different variables in bash?
For example: KNOWN_USER=`syntax that finds the user= field.` echo There is a user= field and the user is mmouse.
UNKNOWN_USER=`syntax that does NOT find the user= field` echo There is NO user= field and an unknown user tried to login.
If been exploring using sed to grab (or not grab) that last field, but haven't hit upon the right syntax yet.
I have searched far and wide but could not seem to find a way to prevent GDM from hiding the password field. I am the only user of my laptop, to login I first need to click the login name to show the password field and then I can enter the password. I would like to have the password field always visible and have focus.
I'm having a bit of a trouble getting a particular field replaced in a host list. I have a MasterHostList which has a comma delimiter for fields and a new line to separate servers.
I then have a file.list file with a grouping of server names. What I need is to search the MasterHostList and for each server that is in the file.list I need to change the fourth field from group1 to group2 without changing the order or position of anything in the MasterHostList. Obviously the above names are arbitrary.
Failed attempts have been: for SERVER in `cat file.list`; do sed /$SERVER/s/,group1,/,group2,/ MasterHostList MasterHostList.tmp && mv -f MasterHostList.tmp MasterHostList; done for SERVER in `cat file.list`;do awk 'BEGIN { FS=OFS="," } /^${SERVER}/ { $4 = "group2" } 1' ./MasterHostList MasterHostList.tmp && mv -f MasterHostList.tmp MasterHostList; done
Both of these would in various output tests find the correct lines, but it wouldn't change them all correctly.
The first field identifies the file name, the second is the search key, and the third is the line number of the file that the search key points to. Any subsequent fields are other key/line number pairs.
As an example, I can search for 4151 (key) from my bash script to identify the file I will have to access, but I also need to capture the line (142) as well, and I can't figure out how to do that using grep, awk or sed (or anything else).