Create the space only in the Third column by awk


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Create the space only in the Third column by awk
# 1  
Create the space only in the Third column by awk

Hi All ,

I am having an input file like this

Input file

Code:
                           r                  s   
                           e                  y   
Pin Numbers                s                  n   
                           eppppppppppppppppppc   
                           taaaaaaaaaaaaaaaaaah   
                           _331111111100000000r   
                           n010145678989234567o   
pattern         offset  
scan0_core_p    2965       11101101010LLLLLHLL0   
                                           ^      
scan0_core_p    2967       11111010111HHLLLHLL0   
                                           ^      
scan0_core_p    2968       11110110011HLLLHHHL0   
                                           ^      
scan0_core_p    2976       11110111100LLHLLHHL0   
                                                   ^    
scan0_core_p    2977       11111011110LHHLLHLL0   
                                                ^    
scan0_core_p    2978       11100010110HHLLLHLL0   
                                             ^

I want to create space in my Third column of the input file
and output should be something like this

Code:
Pin Numbers                                 s                                     n       
                                                   e p p p p p p p p p p p p p p p p p p c       
                                                   t a a a a a a a a a a a a a a a a a a h       
                                                   _ 3 3 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 r       
                                                   n 0 1 0 1 4 5 6 7 8 9 8 9 2 3 4 5 6 7 o       
pattern                   o f f s e t     
scan 0_core_ p             2965                    1 1 1 0 1 1 0 1 0 1 0 L L L L L H L L 0       
                                                                                  ^             
scan0_core_ p              2967                     1 1 1 1 1 0 1 0 1 1 1 H H L L L H L L 0

I am using below stated script
Code:
awk 'BEGIN{FS=OFS=""}  {for (i=1;i<=NF;i++) {if ( i%1==0) $i=$i " "}}1' input.file

But this script is changing the content in other columns also
Could you help me out ?
# 2  
How about
Code:
awk 'NR == 1 {L = index ($0, "r") - 1} {T = substr ($0, L); gsub (/./, "& ", T);  print substr ($0, 1, L), T}' file
                              r                                     s       
                              e                                     y       
Pin Numbers                   s                                     n       
                              e p p p p p p p p p p p p p p p p p p c       
                              t a a a a a a a a a a a a a a a a a a h       
                              _ 3 3 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 r       
                              n 0 1 0 1 4 5 6 7 8 9 8 9 2 3 4 5 6 7 o       
pattern         offset   
scan0_core_p    2965          1 1 1 0 1 1 0 1 0 1 0 L L L L L H L L 0       
                                                              ^             
scan0_core_p    2967          1 1 1 1 1 0 1 0 1 1 1 H H L L L H L L 0       
                                                              ^             
scan0_core_p    2968          1 1 1 1 0 1 1 0 0 1 1 H L L L H H H L 0       
                                                              ^             
scan0_core_p    2976          1 1 1 1 0 1 1 1 1 0 0 L L H L L H H L 0       
                                                                              ^         
scan0_core_p    2977          1 1 1 1 1 0 1 1 1 1 0 L H H L L H L L 0       
                                                                        ^         
scan0_core_p    2978          1 1 1 0 0 0 1 0 1 1 0 H H L L L H L L 0       
                                                                  ^

This User Gave Thanks to RudiC For This Post:
# 3  
Hi Rudic ,

Thanks a lot , could you help me out with brief explanation of this script , It will help me out to counteract similar problems.
# 4  
You present a difficult data structure that cannot be handled with the usual, generic,"normal" awk methods, like fields, field separators, data elements in one line. You have vertical "pin numbers" in varying fields, positional pointers into to a beforementioned line, no indicator where data begin in a line. That makes a somewhat non-standard approach necessary, relying on unconfirmed, unverified assumptions.



Code:
awk '
NR == 1         {L = index ($0, "r") - 1        # on the first line, calculate where the (all space) lead-in part ends (and 
                }                               # the (non-space) data begin)
                {T = substr ($0, L)             # save the "data part" of each line in a temp variable
                 gsub (/./, "& ", T)            # add a space to every single char in the temp var
                 print substr ($0, 1, L), T     # print the first, unmodified part of the line (= $1 and $2),
                }                               # then the "spaced" data part in temp var
' file


Last edited by RudiC; 12-17-2019 at 10:05 AM..
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #810
Difficulty: Medium
The CSS3 RGB Decimal Code for Turquoise is 64,224,218.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Space moving to next column (awk HTML)

Hi I have create a report and have converted the text output to HTML but in the output there is a sentence "The transaction was aborted by the user.", the spaces between this sentence is considered as separate column. How can I overcome the same? I am providing my code, text output and... (7 Replies)
Discussion started by: Dumpi16
7 Replies

2. Shell Programming and Scripting

awk to create variables to pass into a bash loop to create a download link

I have created one file that contains all the necessary info in it to create a download link. In each of the lines /results/analysis/output/Home/Auto_user_S5-00580-6-Medexome_67_032/plugin_out/FileExporter_out.67... (8 Replies)
Discussion started by: cmccabe
8 Replies

3. Shell Programming and Scripting

Create new rows for each column value with awk

Hi, I have the following type of data that is separated by tabs: -2 abandonar abandono abandonas abandona abandonamos abandonis abandonan -4 abandonado abandonada abandonados abandonadas -2 abandona abandonos ... (1 Reply)
Discussion started by: owwow14
1 Replies

4. Shell Programming and Scripting

Help needed to create a UNIX Space monitoring script

Hi All, Its urgent.. pls help me out.. I want to create a KSH which should generate a report with the list of users and the files larger than 5 GB created by them in a direcorty and send autogenerated e-mail to them. my input would be users list,directory path and the file size (say 5 GB) ... (11 Replies)
Discussion started by: anman0523
11 Replies

5. Shell Programming and Scripting

awk Print New Column For Every Two Lines and Match On Multiple Column Values to print another column

Hi, My input files is like this axis1 0 1 10 axis2 0 1 5 axis1 1 2 -4 axis2 2 3 -3 axis1 3 4 5 axis2 3 4 -1 axis1 4 5 -6 axis2 4 5 1 Now, these are my following tasks 1. Print a first column for every two rows that has the same value followed by a string. 2. Match on the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

6. UNIX for Advanced & Expert Users

Need to remove leading space from awk statement space from calculation

I created a awk state to calculate the number of success however when the query runs it has a leading zero. Any ideas on how to remove the leading zero from the calculation? Here is my query: cat myfile.log | grep | awk '{print $2,$3,$7,$11,$15,$19,$23,$27,$31,$35($19/$15*100)}' 02:00:00... (1 Reply)
Discussion started by: bizomb
1 Replies

7. Shell Programming and Scripting

AWK script to create max value of 3rd column, grouping by first column

Hi, I need an awk script (or whatever shell-construct) that would take data like below and get the max value of 3 column, when grouping by the 1st column. clientname,day-of-month,max-users ----------------------------------- client1,20120610,5 client2,20120610,2 client3,20120610,7... (3 Replies)
Discussion started by: ckmehta
3 Replies

8. Solaris

Create user with Restricted Space usage

Hi, What is the command or how to create a user with the restricted usage of space on a disk. Also let me know how to change the limit of the space size allotted in future for the same user. ~Vinodh Kumar V M (3 Replies)
Discussion started by: vino_hymi
3 Replies

9. Filesystems, Disks and Memory

Create file for space Reserve

Hi All, I want to make a 3GB of space reserve on Solaris. Let me know whether there is a way by creating empty file of 3GB so that i can delete that file in future to utilize that space. Or any other better ways for space reserve. -Vinodh' Kumar (4 Replies)
Discussion started by: vino_hymi
4 Replies

10. AIX

column space

Is it possible to give spaces using unix commands at a particular column? eg: 123 56 89(input) 123 56 89(output) (4 Replies)
Discussion started by: rollthecoin
4 Replies

Featured Tech Videos