Get column number with the same character length


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get column number with the same character length
# 8  
Old 12-24-2015
Quote:
Originally Posted by durden_tyler
Just a hunch, did you want something like this?

Column 2 has a consistent width of 4 characters.
Column 4 has a consistent width of 5 characters.

Code:
$ 
$ cat data.log
wtx srtv ty5$q uyrzx
p   56ye iouv  quxzo
ww  uytz rekj  ww#zz
$ 
$ 
$ awk '{
           for (i=1; i<=NF; i++) {
               x[i] = (NR == 1 || length($i) == x[i]) ? length($i) : -1
           }
       }
       END {
           for (i=1; i<=NF; i++) {
               if (x[i] != -1) {
                   print "Column ", i, " has ", x[i], " characters across ", NR, " lines"
               }
           }
       }' data.log
Column  2  has  4  characters across  3  lines
Column  4  has  5  characters across  3  lines
$ 
$

Thank you for this!

---------- Post updated at 09:35 PM ---------- Previous update was at 09:23 PM ----------

Quote:
Originally Posted by durden_tyler
The awk script does identify the first six columns as per your requirement.

Code:
$ 
$ cat -n data.log
     1	Dec=3 21=2 11:13:59=8 jserver-VirtualBox=17 kernel:=7 1=1 VbglR0HGCMInternalCall:=23 vbglR0HGCMInternalDoCall=24 failed.=7 rc=-2=5
     2	Dec=3 21=2 11:13:59=8 jserver-VirtualBox=17 kernel:=7 1=1 VBOXGUEST_IOCTL_HGCM_CALL:=26 64=2 Failed.=7 rc=-2.=6
     3	Dec=3 21=2 12:09:28=8 jserver-VirtualBox=17 kernel:=7 1=1 VbglR0HGCMInternalCall:=23 vbglR0HGCMInternalDoCall=24 failed.=7 rc=-2=5
     4	Dec=3 21=2 12:09:28=8 jserver-VirtualBox=17 kernel:=7 1=1 VBOXGUEST_IOCTL_HGCM_CALL:=26 64=2 Failed.=7 rc=-2.=6
     5	Dec=3 21=2 12:39:44=8 jserver-VirtualBox=17 kernel:=7 1=1 8=1 VbglR0HGCMInternalCall:=23 vbglR0HGCMInternalDoCall=24 failed.=7 rc=-2=5
     6	Dec=3 21=2 12:39:44=8 jserver-VirtualBox=17 kernel:=7 1=1 8=1 VBOXGUEST_IOCTL_HGCM_CALL:=26 64=2 Failed.=7 rc=-2.=6
     7	Dec=3 21=2 14:22:27=8 jserver-VirtualBox=17 kernel:=7 1=1 VbglR0HGCMInternalCall:=23 vbglR0HGCMInternalDoCall=24 failed.=7 rc=-2=5
     8	Dec=3 21=2 14:22:27=8 jserver-VirtualBox=17 kernel:=7 1=1 8=1 VBOXGUEST_IOCTL_HGCM_CALL:=26 64=2 Failed.=7 rc=-2.=6
     9	Dec=3 22=2 10:00:46=8 jserver-VirtualBox=17 kernel:=7 [=1 0.000000]=9 Initializing=12 cgroup=6 subsys=6 cpuset=6
    10	Dec=3 22=2 10:00:46=8 jserver-VirtualBox=17 kernel:=7 [=1 0.000000]=9 Initializing=12 cgroup=6 subsys=6 cpu=3
    11	Dec=3 22=2 10:00:46=8 jserver-VirtualBox=17 kernel:=7 [=1 0.000000]=9 Initializing=12 cgroup=6 subsys=6 cpuacct=7
    12	Dec=3 22=2 10:00:46=8 jserver-VirtualBox=17 kernel:=7 [=1 0.000000]=9 Linux=5 version=7 4.2.0-19-generic=16 (buildd@lgw01-31)=17 (gcc=4 version=7 5.2.1=5 20151010=8 (Ubuntu=7 5.2.1-22ubuntu2)=16 )=1 #23-Ubuntu=10 SMP=3 Wed=3 Nov=3 11=2 11:38:40=8 UTC=3 2015=4 (Ubuntu=7 4.2.0-19.23-generic=19 4.2.6)=6
    13	Dec=3 22=2 10:00:46=8 jserver-VirtualBox=17 kernel:=7 [=1 0.000000]=9 KERNEL=6 supported=9 cpus:=5
    14	Dec=3 22=2 10:00:46=8 jserver-VirtualBox=17 kernel:=7 [=1 0.000000]=9 Intel=5 GenuineIntel=12
    15	Dec=3 22=2 10:00:46=8 jserver-VirtualBox=17 kernel:=7 [=1 0.000000]=9 AMD=3 AuthenticAMD=12
    16	Dec=3 22=2 10:00:46=8 jserver-VirtualBox=17 kernel:=7 [=1 0.000000]=9 NSC=3 Geode=5 by=2 NSC=3
    17	Dec=3 22=2 10:00:46=8 jserver-VirtualBox=17 kernel:=7 [=1 0.000000]=9 Cyrix=5 CyrixInstead=12
    18	Dec=3 22=2 10:00:46=8 jserver-VirtualBox=17 kernel:=7 [=1 0.000000]=9 Centaur=7 CentaurHauls=12
    19	Dec=3 22=2 10:00:46=8 jserver-VirtualBox=17 kernel:=7 [=1 0.000000]=9 Transmeta=9 GenuineTMx86=12
    20	Dec=3 22=2 10:00:46=8 jserver-VirtualBox=17 kernel:=7 [=1 0.000000]=9 Transmeta=9 TransmetaCPU=12
    21	Dec=3 22=2 10:00:46=8 jserver-VirtualBox=17 kernel:=7 [=1 0.000000]=9 UMC=3 UMC=3 UMC=3 UMC=3
$ 
$ 
$ awk '{
           for (i=1; i<=NF; i++) {
               x[i] = (NR == 1 || length($i) == x[i]) ? length($i) : -1
           }
       }
       END {
           for (i=1; i<=NF; i++) {
               if (x[i] != -1) {
                   print "Column ", i, " has ", x[i], " characters across ", NR, " lines"
               }
           }
       }' data.log
Column  1  has  5  characters across  21  lines
Column  2  has  4  characters across  21  lines
Column  3  has  10  characters across  21  lines
Column  4  has  21  characters across  21  lines
Column  5  has  9  characters across  21  lines
Column  6  has  3  characters across  21  lines
$ 
$

Is the output of the script as per your requirement?
Otherwise, did you want this information to be displayed in some other way?
hmm, this works well. only thing is, on some log files, it does not produce any output. when i run it, i get nothing back.

the log i'm running it on is:

Code:
Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19952 duration=0(sec)
Dec 24 19:36:21 nagios002 xinetd[745]: START: livestatus pid=19958 from=::ffff:10.107.68.51
Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19958 duration=0(sec)
Dec 24 19:36:21 nagios002 xinetd[745]: START: livestatus pid=19961 from=::ffff:10.107.68.51
Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19961 duration=0(sec)
Dec 24 19:36:21 nagios002 xinetd[745]: START: livestatus pid=19964 from=::ffff:10.107.68.51
Dec 24 19:36:21 nagios002 xinetd[745]: START: livestatus pid=19967 from=::ffff:10.107.68.53
Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19967 duration=0(sec)
Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19964 duration=0(sec)
Dec 24 19:36:21 nagios002 xinetd[745]: START: livestatus pid=19970 from=::ffff:10.107.68.51
Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19970 duration=0(sec)
Dec 24 19:36:21 nagios002 xinetd[745]: START: livestatus pid=19973 from=::ffff:10.107.68.51
Dec 24 19:36:21 nagios002 xinetd[745]: START: livestatus pid=19976 from=::ffff:10.107.68.53
Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19976 duration=0(sec)
Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19973 duration=0(sec)
Dec 24 19:36:21 nagios002 xinetd[745]: START: livestatus pid=19979 from=::ffff:10.107.68.53
Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19979 duration=0(sec)
Dec 24 19:36:21 nagios002 xinetd[745]: START: livestatus pid=19982 from=::ffff:10.107.68.53
Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19982 duration=0(sec)
Dec 24 19:36:21 nagios002 xinetd[745]: START: livestatus pid=19985 from=::ffff:10.107.68.53
Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19985 duration=0(sec)
Dec 24 19:36:21 nagios002 xinetd[745]: START: livestatus pid=19988 from=::ffff:10.107.68.53
Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19988 duration=0(sec)
Dec 24 19:36:21 nagios002 xinetd[745]: START: livestatus pid=19991 from=::ffff:10.107.68.53
Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19991 duration=0(sec)
Dec 24 19:36:21 nagios002 xinetd[745]: START: livestatus pid=19994 from=::ffff:10.107.68.53
Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19994 duration=0(sec)
Dec 24 19:36:21 nagios002 xinetd[745]: START: livestatus pid=19997 from=::ffff:10.107.68.53
Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19997 duration=0(sec)
Dec 24 19:36:22 nagios002 xinetd[745]: START: livestatus pid=20002 from=::ffff:10.107.66.172
Dec 24 19:36:22 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=20002 duration=0(sec)
Dec 24 19:36:22 nagios002 xinetd[745]: START: livestatus pid=20005 from=::ffff:10.107.66.172
Dec 24 19:36:22 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=20005 duration=0(sec)
Dec 24 19:36:22 nagios002 xinetd[745]: START: livestatus pid=20008 from=::ffff:10.107.66.172
Dec 24 19:36:22 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=20008 duration=0(sec)
Dec 24 19:36:22 nagios002 xinetd[745]: START: livestatus pid=20011 from=::ffff:10.107.68.53
Dec 24 19:36:22 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=20011 duration=0(sec)
Dec 24 19:36:22 nagios002 xinetd[745]: START: livestatus pid=20014 from=::ffff:10.107.68.51
Dec 24 19:36:22 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=20014 duration=0(sec)
Dec 24 19:36:22 nagios002 xinetd[745]: START: livestatus pid=20017 from=::ffff:10.107.66.172
Dec 24 19:36:22 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=20017 duration=0(sec)
Dec 24 19:36:22 nagios002 xinetd[745]: START: livestatus pid=20021 from=::ffff:10.107.66.172
Dec 24 19:36:23 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=20021 duration=1(sec)
Dec 24 19:36:23 nagios002 xinetd[745]: START: livestatus pid=20030 from=::ffff:10.107.68.53
Dec 24 19:36:23 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=20030 duration=0(sec)

# 9  
Old 12-24-2015
Quote:
Originally Posted by SkySmart
...

hmm, this works well. only thing is, on some log files, it does not produce any output. when i run it, i get nothing back.

the log i'm running it on is:

Code:
Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19952 duration=0(sec)
Dec 24 19:36:21 nagios002 xinetd[745]: START: livestatus pid=19958 from=::ffff:10.107.68.51
Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19958 duration=0(sec)
Dec 24 19:36:21 nagios002 xinetd[745]: START: livestatus pid=19961 from=::ffff:10.107.68.51
Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19961 duration=0(sec)
Dec 24 19:36:21 nagios002 xinetd[745]: START: livestatus pid=19964 from=::ffff:10.107.68.51
Dec 24 19:36:21 nagios002 xinetd[745]: START: livestatus pid=19967 from=::ffff:10.107.68.53
Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19967 duration=0(sec)
Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19964 duration=0(sec)
Dec 24 19:36:21 nagios002 xinetd[745]: START: livestatus pid=19970 from=::ffff:10.107.68.51
Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19970 duration=0(sec)
Dec 24 19:36:21 nagios002 xinetd[745]: START: livestatus pid=19973 from=::ffff:10.107.68.51
Dec 24 19:36:21 nagios002 xinetd[745]: START: livestatus pid=19976 from=::ffff:10.107.68.53
Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19976 duration=0(sec)
Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19973 duration=0(sec)
Dec 24 19:36:21 nagios002 xinetd[745]: START: livestatus pid=19979 from=::ffff:10.107.68.53
Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19979 duration=0(sec)
Dec 24 19:36:21 nagios002 xinetd[745]: START: livestatus pid=19982 from=::ffff:10.107.68.53
Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19982 duration=0(sec)
Dec 24 19:36:21 nagios002 xinetd[745]: START: livestatus pid=19985 from=::ffff:10.107.68.53
Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19985 duration=0(sec)
Dec 24 19:36:21 nagios002 xinetd[745]: START: livestatus pid=19988 from=::ffff:10.107.68.53
Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19988 duration=0(sec)
Dec 24 19:36:21 nagios002 xinetd[745]: START: livestatus pid=19991 from=::ffff:10.107.68.53
Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19991 duration=0(sec)
Dec 24 19:36:21 nagios002 xinetd[745]: START: livestatus pid=19994 from=::ffff:10.107.68.53
Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19994 duration=0(sec)
Dec 24 19:36:21 nagios002 xinetd[745]: START: livestatus pid=19997 from=::ffff:10.107.68.53
Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19997 duration=0(sec)
Dec 24 19:36:22 nagios002 xinetd[745]: START: livestatus pid=20002 from=::ffff:10.107.66.172
Dec 24 19:36:22 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=20002 duration=0(sec)
Dec 24 19:36:22 nagios002 xinetd[745]: START: livestatus pid=20005 from=::ffff:10.107.66.172
Dec 24 19:36:22 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=20005 duration=0(sec)
Dec 24 19:36:22 nagios002 xinetd[745]: START: livestatus pid=20008 from=::ffff:10.107.66.172
Dec 24 19:36:22 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=20008 duration=0(sec)
Dec 24 19:36:22 nagios002 xinetd[745]: START: livestatus pid=20011 from=::ffff:10.107.68.53
Dec 24 19:36:22 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=20011 duration=0(sec)
Dec 24 19:36:22 nagios002 xinetd[745]: START: livestatus pid=20014 from=::ffff:10.107.68.51
Dec 24 19:36:22 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=20014 duration=0(sec)
Dec 24 19:36:22 nagios002 xinetd[745]: START: livestatus pid=20017 from=::ffff:10.107.66.172
Dec 24 19:36:22 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=20017 duration=0(sec)
Dec 24 19:36:22 nagios002 xinetd[745]: START: livestatus pid=20021 from=::ffff:10.107.66.172
Dec 24 19:36:23 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=20021 duration=1(sec)
Dec 24 19:36:23 nagios002 xinetd[745]: START: livestatus pid=20030 from=::ffff:10.107.68.53
Dec 24 19:36:23 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=20030 duration=0(sec)

Looks good to me.
Shown below is the execution on the log file you posted:

Code:
$ 
$ cat -n data_2.log
     1	Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19952 duration=0(sec)
     2	Dec 24 19:36:21 nagios002 xinetd[745]: START: livestatus pid=19958 from=::ffff:10.107.68.51
     3	Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19958 duration=0(sec)
     4	Dec 24 19:36:21 nagios002 xinetd[745]: START: livestatus pid=19961 from=::ffff:10.107.68.51
     5	Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19961 duration=0(sec)
     6	Dec 24 19:36:21 nagios002 xinetd[745]: START: livestatus pid=19964 from=::ffff:10.107.68.51
     7	Dec 24 19:36:21 nagios002 xinetd[745]: START: livestatus pid=19967 from=::ffff:10.107.68.53
     8	Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19967 duration=0(sec)
     9	Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19964 duration=0(sec)
    10	Dec 24 19:36:21 nagios002 xinetd[745]: START: livestatus pid=19970 from=::ffff:10.107.68.51
    11	Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19970 duration=0(sec)
    12	Dec 24 19:36:21 nagios002 xinetd[745]: START: livestatus pid=19973 from=::ffff:10.107.68.51
    13	Dec 24 19:36:21 nagios002 xinetd[745]: START: livestatus pid=19976 from=::ffff:10.107.68.53
    14	Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19976 duration=0(sec)
    15	Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19973 duration=0(sec)
    16	Dec 24 19:36:21 nagios002 xinetd[745]: START: livestatus pid=19979 from=::ffff:10.107.68.53
    17	Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19979 duration=0(sec)
    18	Dec 24 19:36:21 nagios002 xinetd[745]: START: livestatus pid=19982 from=::ffff:10.107.68.53
    19	Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19982 duration=0(sec)
    20	Dec 24 19:36:21 nagios002 xinetd[745]: START: livestatus pid=19985 from=::ffff:10.107.68.53
    21	Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19985 duration=0(sec)
    22	Dec 24 19:36:21 nagios002 xinetd[745]: START: livestatus pid=19988 from=::ffff:10.107.68.53
    23	Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19988 duration=0(sec)
    24	Dec 24 19:36:21 nagios002 xinetd[745]: START: livestatus pid=19991 from=::ffff:10.107.68.53
    25	Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19991 duration=0(sec)
    26	Dec 24 19:36:21 nagios002 xinetd[745]: START: livestatus pid=19994 from=::ffff:10.107.68.53
    27	Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19994 duration=0(sec)
    28	Dec 24 19:36:21 nagios002 xinetd[745]: START: livestatus pid=19997 from=::ffff:10.107.68.53
    29	Dec 24 19:36:21 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=19997 duration=0(sec)
    30	Dec 24 19:36:22 nagios002 xinetd[745]: START: livestatus pid=20002 from=::ffff:10.107.66.172
    31	Dec 24 19:36:22 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=20002 duration=0(sec)
    32	Dec 24 19:36:22 nagios002 xinetd[745]: START: livestatus pid=20005 from=::ffff:10.107.66.172
    33	Dec 24 19:36:22 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=20005 duration=0(sec)
    34	Dec 24 19:36:22 nagios002 xinetd[745]: START: livestatus pid=20008 from=::ffff:10.107.66.172
    35	Dec 24 19:36:22 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=20008 duration=0(sec)
    36	Dec 24 19:36:22 nagios002 xinetd[745]: START: livestatus pid=20011 from=::ffff:10.107.68.53
    37	Dec 24 19:36:22 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=20011 duration=0(sec)
    38	Dec 24 19:36:22 nagios002 xinetd[745]: START: livestatus pid=20014 from=::ffff:10.107.68.51
    39	Dec 24 19:36:22 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=20014 duration=0(sec)
    40	Dec 24 19:36:22 nagios002 xinetd[745]: START: livestatus pid=20017 from=::ffff:10.107.66.172
    41	Dec 24 19:36:22 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=20017 duration=0(sec)
    42	Dec 24 19:36:22 nagios002 xinetd[745]: START: livestatus pid=20021 from=::ffff:10.107.66.172
    43	Dec 24 19:36:23 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=20021 duration=1(sec)
    44	Dec 24 19:36:23 nagios002 xinetd[745]: START: livestatus pid=20030 from=::ffff:10.107.68.53
    45	Dec 24 19:36:23 nagios002 xinetd[745]: EXIT: livestatus status=0 pid=20030 duration=0(sec)
$ 
$ 
$ awk '{
           for (i=1; i<=NF; i++) {
               x[i] = (NR == 1 || length($i) == x[i]) ? length($i) : -1
           }
       }
       END {
           for (i=1; i<=NF; i++) {
               if (x[i] != -1) {
                   print "Column ", i, " has ", x[i], " characters across ", NR, " lines"
               }
           }
       }' data_2.log
Column  1  has  3  characters across  45  lines
Column  2  has  2  characters across  45  lines
Column  3  has  8  characters across  45  lines
Column  4  has  9  characters across  45  lines
Column  5  has  12  characters across  45  lines
Column  7  has  10  characters across  45  lines
Column  10  has  15  characters across  45  lines
$ 
$

This User Gave Thanks to durden_tyler For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Add string based on character length

Good day, I am a newbie here and thanks for accepting me I have a task to modify input data where my input data looks like 123|34567|CHINE 1|23|INDIA 34512|21|USA 104|901|INDIASee that my input has two columns with different character length but max length is 5 and minimum length is 0 which... (1 Reply)
Discussion started by: fastlearner
1 Replies

2. UNIX for Dummies Questions & Answers

Select lines based on character length

Hi, I've got a file like this: 22 22:35645163:T:<CN0>:0 0 35645163 T <CN0> 22 rs140738445:20902439:TTTTTTTG:T 0 20902439 T TTTTTTTG 22 rs149602065:40537763:TTTTTTG:T 0 40537763 T TTTTTTG 22 rs71670155:50538408:TTTTTTG:T 0 50538408 T TTTTTTG... (3 Replies)
Discussion started by: zajtat
3 Replies

3. Shell Programming and Scripting

Delimit file based on character length using awk

Hi, I need help with one problem, I came across recently. I have one input file which I need to delimit based on character length. $ cat Input.txt 12345sda231453 asd760kjol62569 sdasw4g76gdf57 And, There is one comma separated file which mentions "start of the field" and "length... (6 Replies)
Discussion started by: Prathmesh
6 Replies

4. Shell Programming and Scripting

awk command to find total number of Special character in a column

How to find total number of special character in a column? I am using awk -f "," '$col_number "*$" {print $col_number}' file.csv|wc -l but its not giving correct output. It's giving output as 1 even though i give no special character? Please use code tags next time for your code and... (4 Replies)
Discussion started by: AjitKumar
4 Replies

5. Shell Programming and Scripting

Need to extract data from Column having variable length column

Hi , I need to extract data from below mentioned data, having no delimiter and havin no fixed column length. For example: Member nbr Ref no date 10000 1000 10202012 200000 2000 11202012 Output: to update DB with memeber nbr on basis of ref no. ... (6 Replies)
Discussion started by: ns64110
6 Replies

6. Shell Programming and Scripting

Add character based on record length

All, I can't seem to find exactly what I'm looking for, and haven't had any luck patching things together. I need to look through a file, and if the record length is not 874, then add 'E' in position 778. Your help is greatly appreciated. (4 Replies)
Discussion started by: CutNPaste
4 Replies

7. Shell Programming and Scripting

Parsing 286 length Character string

Hi Friends, I have .txt file which has 13000 records. Each record is 278 character long. I am using below code to extract the string and it takes almost 10 minutes. Any suggestion please. cat filename.txt|while read line do f1=`echo $line|awk '{print substr($1,1,9)}'` f2=`echo... (6 Replies)
Discussion started by: ppat7046
6 Replies

8. Shell Programming and Scripting

How can use the perl or other command line to calculate the length of the character?

For example, if I have the file whose content are: >HWI-EAS382_30FC7AAXX:7:1:927:1368 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA >HWI-EAS382_30FC7AAXX:7:1:924:1373 ACGAACTTTAAAGCACCTCTTGGCTCGTATGCCGTC I want my output calculate the total length of nucleotide. So my output should look like this:... (1 Reply)
Discussion started by: patrick chia
1 Replies

9. Shell Programming and Scripting

print a file with one column having fixed character length

Hi guys, I have tried to find a solution for this problem but couln't. If anyone of you have an Idea do help me. INPUT_FILE with three columns shown to be separated by - sign A5BNK723NVI - 1 - 294 A7QZM0VIT - 251 - 537 A7NU3411V - 245 - 527 I want an output file in which First column... (2 Replies)
Discussion started by: smriti_shridhar
2 Replies

10. Shell Programming and Scripting

Using Awk script to check length of a character

Hi All , I am trying to build a script using awk that checks columns of the înput file and displays message if the column length exceeds 35 char. i have tried the below code but it does not work properly (2 Replies)
Discussion started by: amit1_x
2 Replies
Login or Register to Ask a Question