Sample data file
080914|xx xxx
080915|xxx x
080916|xx xx
080917|xxxxxx
080918|xxxxxx
080919|x x
This is so simple I am sure but I have reached a bit of a wall. I want to update $2 (FS="|" at will. Here is the catch though. If the last record $2=="x x " and I want it to be updated to "x x x", how would I do that? IN other words I want it to go from x-space-space-x-space to x-space-space-x-space-x or maybe even x-space-space-x-space-space. I hope my description is good enough but if you require more info, let me know. In this file, $2 will never be longer than 6 bytes but if it is the last record, it could vary from 0-6 bytes and I just want to update $2 with an additional x or space(s)!
I don't understand exactly what the criteria are for modifying field 2, but to do just the change you gave as an example, the following awk program should do it. Also, you said the file has 3 fields but your example only has 2.
BEGIN { FS="|"}
{
if ($2 == "x x " {
$2 = "x x x"
}
print
}
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.