Sponsored Content
Top Forums Shell Programming and Scripting Update specific field in a line of text file Post 302755461 by Scrutinizer on Sunday 13th of January 2013 08:30:12 AM
Old 01-13-2013
I tried to reproduce this using variable subj, but I got:

Code:
$ awk -F: '{if($1~subj && $2~lec){$3=newMark}}1' subj="subject1" lec="LecturerA" newMark=100 OFS=":" infile
subject1:LecturerA:100

subject2:LecturerA:40
$ b=subject1 lect=LecturerA mark=100
$ awk -F: '{if($1~subj&&$2~lec){$3=newMark}}1' subj="$sb" lec="$lect" newMark="$mark" OFS=":" infile
subject1:LecturerA:100

subject2:LecturerA:40

What is your OS and version?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Adding specific text and spaces to each line in a text file

Hi, I wanted to add specific text to each row in a text file containing three rows. Example: 0 8 7 6 5 5 7 8 9 0 7 9 7 8 9 0 1 2 And I want to add a 21 at the beginning of the first row, and blank spaces at the beginning of the second two rows. To get this: 21 0 8 7 6 5 5 7 8... (4 Replies)
Discussion started by: hertingm
4 Replies

2. Shell Programming and Scripting

how to cut a field of a line in a text file?

Hi, I have text file which contains lines like : a/a/a/a/.project b/b/b/b/b/.project c/c/c/.project d/.project e/e/e/e/.project i want for all lines the last word .project should be removed and the file should look like : a/a/a/a/ b/b/b/b/b/ c/c/c/ .... how to proceed... (7 Replies)
Discussion started by: bhaskar_m
7 Replies

3. Shell Programming and Scripting

Update a specific line in a file while reading sequentially

All, I know this is a very naive question but I could not find a way to get this working! I have a file with values like input.file Value1 Value2 server1/mylogin,mypasswd Value3 Value4 And in my code, I am reading the file line by line and processing it. #! /bin/ksh... (6 Replies)
Discussion started by: bharath.gct
6 Replies

4. Shell Programming and Scripting

replacing field in specific line in a file

Hi, I know there are lots of threads on replacing text within files, usually using sed or awk. However, I find it hard to adapt examples that I found to my specific case. I am kind of new to UNIX and have hard times learning the syntax either for sed or awk so I would appreciate any help. Here's... (5 Replies)
Discussion started by: vytenis
5 Replies

5. Shell Programming and Scripting

Using awk to read a specific line and a specific field on that line.

Say the input was as follows: Brat 20 x 1000 32rf Pour 15 p 1621 05pr Dart 10 z 1111 22xx My program prompts for an input, what I want is to use the input to locate a specific field. Like if I type in, "Pou" then it would return "Pour" and just "Pour" I currently have this line but it is... (6 Replies)
Discussion started by: Bungkai
6 Replies

6. Shell Programming and Scripting

Replace specific field on specific line sed or awk

I'm trying to update a text file via sed/awk, after a lot of searching I still can't find a code snippet that I can get to work. Brief overview: I have user input a line to a variable, I then find a specific value in this line 10th field in this case. After asking for new input and doing some... (14 Replies)
Discussion started by: crownedzero
14 Replies

7. Shell Programming and Scripting

Extract specific line in an html file starting and ending with specific pattern to a text file

Hi This is my first post and I'm just a beginner. So please be nice to me. I have a couple of html files where a pattern beginning with "http://www.site.com" and ending with "/resource.dat" is present on every 241st line. How do I extract this to a new text file? I have tried sed -n 241,241p... (13 Replies)
Discussion started by: dejavo
13 Replies

8. Shell Programming and Scripting

Perl to update field based on a specific set of rules

In the perl below, which does execute, I am having trouble with the else in Rule 3. The digit in f{8} is extracted and used to update f accordinly along with the value in f. There can be either - * or + before the number that is extracted but the same logic applies, that is if the value is greater... (5 Replies)
Discussion started by: cmccabe
5 Replies

9. Shell Programming and Scripting

Update a specific field in file with Variable value based on other Key Word

I have an input file with A=xyz B=pqr I would want the value in Second Field (xyz or pqr) updated with a value present in Shell Variable based on the value passed in the first field. (A or B ) while read line do NEW_VALUE = `some functionality done on $line` If $line=First Field-... (1 Reply)
Discussion started by: infernalhell
1 Replies

10. UNIX for Beginners Questions & Answers

awk to update file with partial matching line in another file and append text

In the awk below I am trying to cp and paste each matching line in f2 to $3 in f1 if $2 of f1 is in the line in f2 somewhere. There will always be a match (usually more then 1) and my actual data is much larger (several hundreds of lines) in both f1 and f2. When the line in f2 is pasted to $3 in... (4 Replies)
Discussion started by: cmccabe
4 Replies
DN(3)							User Contributed Perl Documentation						     DN(3)

NAME
X500::DN - handle X.500 DNs (Distinguished Names), parse and format them SYNOPSIS
use X500::DN; my $dn = X500::DN->ParseRFC2253 ('cn=John Doe, o=Acme\, Inc., c=US') or die; print $dn->getRFC2253String(), " "; $dn = new X500::DN (new X500::RDN ('c'=>'US'), new X500::RDN ('cn'=>'John Doe')); my $rdn0 = $dn->getRDN (0); my $c = $rdn0->getAttributeValue ('c'); NOTE
The RFC 2253 syntax is explicitely backwards in relation to the ASN.1 SEQUENCE. So the RFC 2253 string "cn=John Doe, c=US" has the same meaning as the X.500 string "c=US, cn=John Doe". The X500::DN objects keep the RDNs in X.500 order! DESCRIPTION
This module handles X.500 DNs (Distinguished Names). Currently, it parses DN strings formatted according to RFC 2253 syntax into an internal format and produces RFC 2253 formatted string from it. Methods o $object = new X500::DN (rdn, rdn, ...); Creates a DN object from zero or more arguments of type X500::RDN. o $object = X500::DN->ParseRFC2253 ('cn=John Doe, o=Acme\, Inc., c=US'); Creates a DN object from an RFC 2253 formatted DN string notation. o $object->getRFC2253String(); Returns the DN as a string formatted according to RFC 2253 syntax. o $object->getOpenSSLString(); Returns the DN as a string formatted suitable for "openssl req -subj" and "openssl ca -subj". o $object->getX500String(); Returns the DN as a string formatted according to X.500 syntax. NOTE: This is a hack, there is no definition for a X.500 string syntax! o $object->hasMultivaluedRDNs(); Returns whether the DN contains multi-valued RDNs. o $object->getRDN (num); Returns the DN's RDN at position num as an X500::RDN object. num starts with 0, which will return the first RDN in ASN.1 SEQUENCE order. o $object->getRDNs(); Returns the DN's RDNs, a list of objects of type X500::RDN, in ASN.1 SEQUENCE order. EXPORT None. BUGS
o Due to Parse::RecDescent's greedyness, white space after attribute values gets into the parsed value. It might be possible to work around this. AUTHOR
Robert Joop <yaph-070708@timesink.de> COPYRIGHT
Copyright 2002 Robert Joop. All Rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO
X500::RDN, perl. HISTORY
Early 2002: First idea, discussed on comp.lang.perl.moderated April 2002: First public release, 0.15 perl v5.12.1 2007-07-08 DN(3)
All times are GMT -4. The time now is 05:08 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy