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
PPMIMGVQUANT(1) 					      General Commands Manual						   PPMIMGVQUANT(1)

NAME
ppmimgvquant - palette quantifier for Pilot Image Viewer pgm files, version 2.0. SYNOPSIS
ppmimgvquant [-4] [-h] [-v] [ppmquant options] DESCRIPTION
ppmimgvquant just calls ppmquant(1) with the following map file: P3 4 1 255 0 0 0 85 85 85 170 170 170 255 255 255 If you specify -4, then we use this map file: P3 16 1 255 0 0 0 17 17 17 34 34 34 51 51 51 68 68 68 85 85 85 102 102 102 119 119 119 136 136 136 153 153 153 170 170 170 187 187 187 204 204 204 221 221 221 238 238 238 255 255 255 The ppmquant(1) output is also passed through ppmtopgm(1) to ensure a graymap output file. OPTIONS
-4 Convert to 4 depth image (for Palm IIIx/V). -h Display a usage message and exit. -v Display the version number and exit. All other switches are passed to ppmquant(1). SEE ALSO
imgvinfo(1), imgvtopnm(1), imgvview(1), pbmtoimgv(1), pgmtoimgv(1), ppmquant(1), ppmtopgm(1), pbm(5), pgm(5). BUGS
Bug reports should be sent to Eric A. Howe (mu@trends.net). LICENSE
Copyright (C) 1997,1998 Eric A. Howe <http://www.trends.net/~mu>. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MER- CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Sept 1997 PPMIMGVQUANT(1)
All times are GMT -4. The time now is 05:46 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy