Find the answer to your Linux question:
Results 1 to 2 of 2
Hi Everybody I have the following file with 5 fields which are seperated by '|' Eno |Ename |Designation |dept |sal 5000 |Sharma |Director |Production |5000 6000 |guptha |Director |personnel |20000 ...
  1. #1
    Linux Newbie
    Join Date
    Jul 2004
    Posts
    143

    red sed

    Hi Everybody

    I have the following file with 5 fields which are seperated by '|'

    Eno |Ename |Designation |dept |sal
    5000 |Sharma |Director |Production |5000
    6000 |guptha |Director |personnel |20000

    My requirement is I want to print 1st and 5th fields and 5000 in sal field should be replaced with 10000.

    My output will be like this
    Eno sal
    5000 10000
    6000 20000

    Please help me.

    Thanks InAdvance,
    Mummaneni.

  2. #2
    Just Joined!
    Join Date
    Aug 2007
    Posts
    37
    That's a job for awk not sed:
    Code:
    awk -F"|" '{if ($5==5000) $5=10000; print $1"\t"$5}' input_file

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...