Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

does any one have a sample

Status
Not open for further replies.

lebond

Programmer
May 24, 2002
4
US
I want to read a file, if I find a line with a business unit=XXX, Responsibility=YYY, I want to add XXXYYY to the end of the line. I want to output file to be in the same order as the input file and not alter any of the other lines, just the headers that will have different business unit and responsibility values.

Does anyone have anything similiar to this.

Thanks
LEBOND
 
If it's a nice and neat problem with the line containing
only the string you specified:

awk '
/business unit=XXX, Responsibility=YYY/ {
$0 = $0 " XXXYYY"
}
{
print
}' file

should work.

If not, send part of a sample file.
 
The XXX and YYY values change with each header line.

I have tried to code an if statement and substr the values from the line to the end of the line but nothing is working for me.

Any other input would be greatly appreciated.

Thanks
LEBOND
 
Hi Lebond,

This solution assumes that XXX and YYY are always 3 characters long.
Code:
{
  if (substr($1,1,5) == "unit=" && substr($2,1,15) == "Responsibility=") {
    $0 = $0 substr($1,6,3) substr($2,16,3)
  }
  print
}
If this doesn't solve the problem, I agree with marsd that you need to post some sample data. CaKiwi
 
Thank you so much Cakiwi and Marsd.... I was messing up the if statement. I got it working now.

Lebond

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top