Using awk And/Or sed To Edit Fourth Field Of File 
Author Message
 Using awk And/Or sed To Edit Fourth Field Of File

Does anyone know how I could use awk and/or sed to change the fourth field
of selected lines in a file?

I am trying to change the 4th field of all the lines that start with bkpadm
in the /etc/passwd file on a Unix system.  The 4th field present values are
different from line to line.   My goal is to change these selected lines to
contain the same value in the 4th field.   There are alot of lines to modify
therefore I was trying to use sed and awk to do this but I have had no luck.
The field separator is a ":".

Any ideas??



Thu, 27 May 2004 07:09:02 GMT  
 Using awk And/Or sed To Edit Fourth Field Of File

00:09:

[SNIP of repeated question in comp.unix.shell comp.unix.question]

I allready answered you question on cuq.

Please read: http://www.cs.tut.fi/~jkorpela/usenet/xpost.html

Michael Heiming



Thu, 27 May 2004 08:33:53 GMT  
 Using awk And/Or sed To Edit Fourth Field Of File

Quote:

>Does anyone know how I could use awk and/or sed to change the fourth field
>of selected lines in a file?

>I am trying to change the 4th field of all the lines that start with bkpadm
>in the /etc/passwd file on a Unix system.  The 4th field present values are
>different from line to line.   My goal is to change these selected lines to
>contain the same value in the 4th field.   There are alot of lines to modify
>therefore I was trying to use sed and awk to do this but I have had no luck.
>The field separator is a ":".

>Any ideas??

awk 'BEGIN{FS=OFS=":";new="your-value"}/^bkpadm/{$4=new} 1 ' /etc/passwd

modify "your-value" and redirect the output as appropriate.

Chuck Demas

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.



Thu, 27 May 2004 20:44:06 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. deleting records in a file using AWK, SED, or kshell

2. How to handle comma in the fields winthin a csv file using awk

3. Extracting hyphenated words using sed/awk

4. how to insert a comma using either sed or awk

5. join a range of lines using awk/sed

6. extracting top 100 data using awk or sed/perl

7. Q: Directory highlighting using sed/awk?

8. deleting records using AWK, SED, etc.

9. Question: How to remove END OF LINE using AWK or SED

10. Using awk & sed from tcl/tk

11. log file processing - awk or sed

12. How to get info from a file with sed/awk/perl

 

 
Powered by phpBB® Forum Software