Sponsored Content
Top Forums Shell Programming and Scripting Bash detecting number of digits in line Post 302950145 by RavinderSingh13 on Tuesday 21st of July 2015 10:51:25 AM
Old 07-21-2015
Hello firefox2k2,

Following may help you in same, let me know if you have any queries.
Code:
 awk -F":" -vs1="'" '{sub(/\+/," ",$1);sub(/DTM/,"DTM07",$1);sub(s1,X,$NF);if(length($NF)==2 || length($NF)==3 && $1 ~ /DTM07/){printf "%s %d %15d\n", $1, $2, $3}};{if($1 ~ /QTY/){sub(/\+/,":",$1);printf "%s%015s%s\n", $1, $2, $3}}' Input_file

Output will be as follows.
Code:
DTM07 64 20160601             102
DTM07 63 20160630             102
QTY 113000000000000050PCE
DTM07 64 20160701             102
DTM07 63 20160731             102
QTY 113000000000000050PCE
DTM07 64 20160801             102
DTM07 63 20160831             102
QTY 113000000000000000PCE
DTM07 64 20160901             102
DTM07 63 20160930             102
QTY 113000000000000050PCE
DTM07 64 20161001             102
DTM07 63 20161031             102
QTY 113000000000000000PCE
DTM07 64 20161101             102
DTM07 63 20161130             102

EDIT: Adding a non one-liner form for same.
Code:
 awk -F":" -vs1="'" '{
                        sub(/\+/," ",$1);
                        sub(/DTM/,"DTM07",$1);
                        sub(s1,X,$NF);
                        if(length($NF)==2 || length($NF)==3 && $1 ~ /DTM07/)
                    {
                        printf "%s %d %15d\n", $1, $2, $3
                    }
                    };
                    {
                        if($1 ~ /QTY/)
                    {
                        sub(/\+/,":",$1);
                        printf "%s%015s%s\n", $1, $2, $3
                    }
                    }
                   ' Input_file

Thanks,
R. Singh

Last edited by RavinderSingh13; 07-21-2015 at 12:03 PM.. Reason: Added a non one-liner form for solution on same now
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Count number of digits in a word

Hi all Can anybody suggest me, how to get the count of digits in a word I tried WORD=abcd1234 echo $WORD | grep -oE ] | wc -l 4 It works in bash command line, but not in scripts :mad: (12 Replies)
Discussion started by: ./hari.sh
12 Replies

2. Shell Programming and Scripting

Printing the line number in bash script

Hi, I would like to know how do I print the line # in a script. My requirement is, I have a script which is about ~5000 lines long. If there are any errors happen I just exit. And I would like to add the line # of the script where the error happened. Thanks, (6 Replies)
Discussion started by: suryaemlinux
6 Replies

3. Shell Programming and Scripting

number of digits after decimal

Hi All, I have a file of decimal numbers, cat file1.txt 1.1382666907 1.2603107334 1.6118799297 24.4995857056 494.7632588468 560.7633734425 ..... I want to see the output as only 7 digits after decimal (5 Replies)
Discussion started by: senayasma
5 Replies

4. Shell Programming and Scripting

Detecting key combination in bash

I need to grab key combination from a bash script and store it in a variable. Is there any way to do this? Thanks in advance! (1 Reply)
Discussion started by: prism1
1 Replies

5. UNIX for Dummies Questions & Answers

How to delete lines above a certin line number in bash shell

Hi, I have written a script that returns the line number of the pattern i want and i stored the line number in a variable(getlinenumber).Now i want to delete all the lines in a file above this line number which is stored in a variable. i am using sed '1,$getlinenumberd' > file1.txt which is... (2 Replies)
Discussion started by: learninguser235
2 Replies

6. UNIX for Dummies Questions & Answers

How to delete lines above a certin line number in bash shell

Hi, I have written a script that returns the line number of the pattern i want and i stored the line number in a variable.Now i want to delete all the lines in a file above this line number which is stored in a variable. i am using sed '1,$getlinenumberd' > file1.txt which is not working(wrog... (5 Replies)
Discussion started by: learninguser235
5 Replies

7. Shell Programming and Scripting

summing the digits of a binary nuMBER

please help me write a perl program to find the difference of 1 and zeros of a 6 digit binary number. eg If input is 111100 expected output +2 if input is 000011 expected output -2 input is 000111 expected output 0 (2 Replies)
Discussion started by: dll_fpga
2 Replies

8. Shell Programming and Scripting

extracting Number variable and the following digits.

HI all, I have output of something like this: crab: ExitCodes Summary >>>>>>>>> 12 Jobs with Wrapper Exit Code : 50117 List of jobs: 1-12 See https:///twiki/something/ for Exit Code meaning crab: ExitCodes Summary >>>>>>>>> 5 Jobs with Wrapper Exit Code : 8001 List of... (20 Replies)
Discussion started by: emily
20 Replies

9. Shell Programming and Scripting

awk changes to cut number of digits

HCPM1ONDB00014800011800000589009211201 L201307022013070228AUD 00000000031. 000965105800000000000000000000000 MOBITV KEYA ... (4 Replies)
Discussion started by: mirwasim
4 Replies

10. Shell Programming and Scripting

Find number of digits in a word

HI, Can you tell me how to find the number of digits in a word. $cat data.txt +123456ad 87645768 Output should be 6 8 (5 Replies)
Discussion started by: ashwin3086
5 Replies
colcrt(1)						      General Commands Manual							 colcrt(1)

Name
       colcrt - filter nroff output for CRT previewing

Syntax
       colcrt [-] [-2] [file...]

Description
       The  command provides virtual half-line and reverse line feed sequences for terminals without such capability, and on which overstriking is
       destructive.  Half-line characters and underlining (changed to dashing `-') are placed on new lines in between the normal output lines.

Options
       -  Suppresses all underlining.  It is especially useful for previewing allboxed tables from

       -2 Causes half-lines to be printed, double spacing the output.  Normally, a minimal space output format is used which will  suppress  empty
	  lines.   The	program  never	suppresses  two  consecutive empty lines, however.  The -2 option is useful for sending output to the line
	  printer when the output contains superscripts and subscripts which would otherwise be invisible.

Examples
       A typical use of would be:
       tbl exum2.n | nroff -ms | colcrt - | more

Restrictions
       Can't back up more than 102 lines.

       General overstriking is lost; as a special case `|' overstruck with `-' or underline becomes `+'.

       Lines are trimmed to 132 characters.

See Also
       col(1), more(1), nroff(1), ul(1)

																	 colcrt(1)
All times are GMT -4. The time now is 12:51 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy