Today (Saturday) We will make some minor tuning adjustments to MySQL.

You may experience 2 up to 10 seconds "glitch time" when we restart MySQL. We expect to make these adjustments around 1AM Eastern Daylight Saving Time (EDT) US.


Help me in awk or sed in UNIX

Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Help me in awk or sed in UNIX

I have a fixed length file that looks like
Code:
a@ a00 a00000 a00 a000000            a00  a0000   a0000     a00000000   a01
a@ a1 a2 a11 a22 a12 a13 a44 a45                     a54      a65    a76  a77
a@    a1 a3 a6    a7     a9      a8     a2  a7          a8    a8      a9   a0
b@ b00 b00000 b00 b000000            b00  b0000   b0000     b00000000   b01
b@ b1 b2 b11 b22 b12 b13 b44 b45                     b54      b65    b76  b77
b@    b1 b3 b6    b7     b9      b8     b2  b7          b8    b8      b9   b0
c@ c00 c00000 c00 c000000            c00  c0000   c0000     c00000000   c01
c@ c1 c2 c11 c22 c12 c13 c44 c45                     c54      c65    c76  c77
c@    c1 c3 c6    c7     c9      c8     c2  c7          c8    c8      c9   c0
d@ d00 d00000 d00 d000000            d00  d0000   d0000     d00000000   d01
d@ d1 d2 d11 d22 d12 d13 d44 d45                     d54      d65    d76  d77
d@    d1 d3 d6    d7     d9      d8     d2  d7          d8    d8      d9   d0

In this file , 3 consecutive lines look same for a@,b@,c@ d@
If in the 2nd column of 2nd row of every such segment contains (, then I have to append 'new' after the 5th column
of the 1st line of that segment such that the next word of the appended word stayed in the previous position.

Like if the c segment looks like [2nd column of 2nd row contains ')' ]
Code:
c@ c00 c00000 c00 c000000            c00  c0000   c0000     c00000000   c01
c@ c1 c( c11 c22 c12 c13 c44 c45                     c54      c65    c76  c77
c@    c1 c3 c6    c7     c9      c8     c2  c7          c8    c8      c9   c0

Then 5th column of the 1st line of that segment should look like
Code:
c@ c00 c00000 c00 c000000new         c00  c0000   c0000     c00000000   c01

So new file should look like
Code:
a@ a00 a00000 a00 a000000            a00  a0000   a0000     a00000000   a01
a@ a1 a2 a11 a22 a12 a13 a44 a45                     a54      a65    a76  a77
a@    a1 a3 a6    a7     a9      a8     a2  a7          a8    a8      a9   a0
b@ b00 b00000 b00 b000000            b00  b0000   b0000     b00000000   b01
b@ b1 b2 b11 b22 b12 b13 b44 b45                     b54      b65    b76  b77
b@    b1 b3 b6    b7     b9      b8     b2  b7          b8    b8      b9   b0
c@ c00 c00000 c00 c000000new         c00  c0000   c0000     c00000000   c01
c@ c1 c( c11 c22 c12 c13 c44 c45                     c54      c65    c76  c77
c@    c1 c3 c6    c7     c9      c8     c2  c7          c8    c8      c9   c0
d@ d00 d00000 d00 d000000            d00  d0000   d0000     d00000000   d01
d@ d1 d2 d11 d22 d12 d13 d44 d45                     d54      d65    d76  d77
d@    d1 d3 d6    d7     d9      d8     d2  d7          d8    d8      d9   d0

Please let me know if I can do the change using awk or sed

Last edited by Franklin52; 06-07-2016 at 09:28 AM.. Reason: Please use code tags
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
UNIX for learning sed/awk/grep..etc..
jeffs42885
Greetings all, I am looking for a version of Linux that I can practice my scripting skills on. Currently, I support a massive system running on AIX. I want to do more with awk, sed, grep, and even perl. I am looking for something I can throw on a VM on my personal laptop and mess around with....... UNIX for Beginners Questions & Answers
5
UNIX for Beginners Questions & Answers
Help me in awk or sed in UNIX
RJG
I have a fixed length file a.txt that looks like a@ a00 a00000 a00 a000000 a00 a0000 a0000 a00000000 a01 a@ a1 a2 a11 a22 a12 a13 a44 a45 a54 a65 a76 a77 a@ a1 a3 a6 a7 a9 a8 a2 a7 a8 a8 a9 a0 b@ b00...... Shell Programming and Scripting
7
Shell Programming and Scripting
Join the line on delimiter using sed/awk in UNIX
jinixvimal
I've input as , abcd| ef 123456| 78| 90 Desired output as, abcdef 1234567890 Anyone please give the solution.... Shell Programming and Scripting
5
Shell Programming and Scripting
What should be precedence of using awk, sed, head and tail in UNIX?
Prathmesh
Hi All, I am new to unix. In this forum some days back, I have read something like below: 1) Do not use perl if awk can do your work. 2) Do not use awk if sed can do your work. . . . I do not re-collect the whole thing. I think it is good to know the precedence of using these...... UNIX for Dummies Questions & Answers
2
UNIX for Dummies Questions & Answers
unix awk/sed program
mnnarendra
i need a sample unix awk/sed program to replace param3 in a file. i have sample file a.dat with the following format/length (week 8, sku 20, store 20 and qty 8). all store id's which end with _2 needs to be replaced with div id 2. all store id's which end with _1 needs to be replaced with div id...... UNIX for Advanced & Expert Users
4
UNIX for Advanced & Expert Users

Featured Tech Videos