Finding the length of a string in a field


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding the length of a string in a field
# 1  
Old 07-26-2011
Finding the length of a string in a field

I have a field MPN-BANK-NUMBERO:006,00:N in a file FILE1

How can i display the length of the Bank Number.Any idea ?
The output shud take the following format

FILE 1 6
Where 1 is the starting position and 6 is the Ending position.
# 2  
Old 07-26-2011
You keep posting the same issue in a different way:
https://www.unix.com/shell-programmin...tion-file.html
# 3  
Old 07-26-2011
Quote:
Originally Posted by Shell_Life
You keep posting the same issue in a different way:
https://www.unix.com/shell-programmin...tion-file.html

Am new to this site. Am unaware of rules and regulations. Sorry btw
# 4  
Old 07-26-2011
pls post sample input and expected output.

is this the input:
Code:
MPN-BANK-NUMBERO:006,00:N ?

If so, what output you are expecting from it.
# 5  
Old 07-26-2011
Quote:
Originally Posted by panyam
pls post sample input and expected output.

is this the input:
Code:
MPN-BANK-NUMBERO:006,00:N ?

If so, what output you are expecting from it.
Input takes the following format :
MPN-BANK-NUMBERO:006,00:N
MPN-515-ACCOUNNUMBERO:018,00:N

Where BANK NUMBER is of 6 characters(1-6) in length and ACC NUM is of 18 characters(7-24) in length.



Output shud be in the below mentioned format:

*FILENAME*,1,6,7,24
# 6  
Old 07-26-2011
What is *one* anonymized line from the input file, please. Stop using words where there's supposed to be numbers, please. Smilie Smilie
# 7  
Old 07-26-2011
Quote:
Originally Posted by Nitrodist
What is *one* anonymized line from the input file, please. Stop using words where there's supposed to be numbers, please. Smilie Smilie

Sorry about that. I dint get you initially. Could you please elaborate it a bit.

FILE1 has the following 2 fields
MPN-BANK-NUMBERO:006,00:N(6 characters in length)
MPN-515-ACCOUNT_NUMBERO:018,00:N (18 Characters in length)

Now my requirement is to find the starting position and ending position of the BANK NUMBER and the ACCOUNT NUMBER of each file concatenated with the file name which gives the below mentioned output:

FILE1,1,6,7,24 where BANK NUMBER is of 6 characters(1-6) in length and ACC NUM is of 18 characters(7-24) in length.

Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding difference between two columns of unequal length

Hi, I have two files which look like this cat waitstate.txt 18.2 82.1 cat gostate.txt 5.6 5.8 6.1 6.3 6.6 6.9 7.2 7.5 (4 Replies)
Discussion started by: jamie_123
4 Replies

2. Shell Programming and Scripting

Replace a field with a character as per the field length

Hi all, I have a requirement to replace a field with a character as per the length of the field. Suppose i have a file where second field is of 20 character length. I want to replace second field with 20 stars (*). like ******************** As the field is not a fixed one, i want to do the... (2 Replies)
Discussion started by: gani_85
2 Replies

3. Shell Programming and Scripting

Finding the length of the longest column

Hi, I am trying to figure out how to get the length of the longest column in the entire file (because the length varies from one row to the other) I was doing this at first to check how many fields I have for the first row: awk '{print NF; exit}' file Now, I can do this: awk '{ if... (4 Replies)
Discussion started by: MIA651
4 Replies

4. Shell Programming and Scripting

Flat file-make field length equal to header length

Hello Everyone, I am stuck with one issue while working on abstract flat file which i have to use as input and load data to table. Input Data- ------ ------------------------ ---- ----------------- WFI001 Xxxxxx Control Work Item A Number of Records ------ ------------------------... (5 Replies)
Discussion started by: sonali.s.more
5 Replies

5. Shell Programming and Scripting

Finding the records with a specified length

I have a sample txt file which has different variable lengths of 2,10,3,15. What is the command that I need use in order to get the record count that has length '3' Thanks (3 Replies)
Discussion started by: bobby1015
3 Replies

6. UNIX for Dummies Questions & Answers

Read a string with leading spaces and find the length of the string

HI In my script, i am reading the input from the user and want to find the length of the string. The input may contain leading spaces. Right now, when leading spaces are there, they are not counted. Kindly help me My script is like below. I am using the ksh. #!/usr/bin/ksh echo... (2 Replies)
Discussion started by: dayamatrix
2 Replies

7. Shell Programming and Scripting

Help with finding length of a field

I have a pipe delimited file. I need to check that the first and second fields are 5 characters long and if not i need to append 0 in front of them to make them 5 characters long. can some body let mwe know how i can find the length of the two fields and then make them 5 characters long if they... (6 Replies)
Discussion started by: dsravan
6 Replies

8. Shell Programming and Scripting

sed problem - replacement string should be same length as matching string.

Hi guys, I hope you can help me with my problem. I have a text file that contains lines like this: 78 ANGELO -809.05 79 ANGELO2 -5,000.06 I need to find all occurences of amounts that are negative and replace them with x's 78 ANGELO xxxxxxx 79... (4 Replies)
Discussion started by: amangeles
4 Replies

9. UNIX for Dummies Questions & Answers

Validating fixed length field...

What's wrong with this part of my script? I just want to put each column from a fixed length file into a variable so I can validate each field later in the script. exec< myfile.dat while read afile; do a=`echo $(echo $afile |cut -c1-10)` echo "$a" b=`echo $(echo $afile |cut -c11-20)`... (12 Replies)
Discussion started by: giannicello
12 Replies

10. Shell Programming and Scripting

Finding out the length of a string held within a variable

:confused: Does anyone know which command I can use to find out the length of a string held within a variable? (5 Replies)
Discussion started by: dbrundrett
5 Replies
Login or Register to Ask a Question