Squence number manipulation in Shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Squence number manipulation in Shell
# 1  
Old 12-25-2017
Squence number manipulation in Shell

Hello Forum,

I am receiving a file daily like ASAD but at the end there is a counter like 0012 (4 digits) so my every next file +1
I want to write a control script and check the last sequence number.Let's say If I receive a file ASAD0012 then after receiving this file I wan to say that next seq_number is "0013"

How can manipulate this logic?

Thx AllSmilie
# 2  
Old 12-25-2017
Welcome to the forum.

More details, please.

If your CWD is the target directory, would
Code:
printf "%04d\n"  $(( $(ls -r ASAD* | sed 's/ASAD0*//; q; ') + 1 ))

do what you need?
# 3  
Old 12-26-2017
Thank You RudiC;

What if I receive the file "ASAD9999" Then Can I say bext_sequence_number is:10000
# 4  
Old 12-26-2017
What would be the result if you applied the proposed code snippet?
# 5  
Old 12-26-2017
Code:
printf "%04d\n"  $(( $(ls -1rt KSAD9*|tail -1 | sed 's/KSAD9*//; q; ') + 1 ))

Result:0000

---------- Post updated at 02:19 PM ---------- Previous update was at 02:18 PM ----------

it worked for my received file name as KSAD9999

and result is :0000

---------- Post updated at 02:23 PM ---------- Previous update was at 02:19 PM ----------

However I can parse the seq number but If I receive the like KSAD1000
Then I can get 1001 is the next_seq_number.

BUT My actual received files as like KSAD0042 Then I can not get as my next_seq_number is:0043

that is mu problem

Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 12-26-2017 at 07:32 AM.. Reason: Added CODE tags.
# 6  
Old 12-26-2017
That is not what I posted. If you feel free to modify the proposals, feel free as well to debug.

With a file ASAD9999, my above proposal yields 10000
With a file ASAD0042, my above proposal yields 0043
This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

File manipulation place 0 before the number using sed

I'm new with sed, and i am really confused with slashes, backslashes, parentheses, I've tried reading some beginner's guide, but still trouble fixing this problem, do you have any tips where or what to read to learn more about sed? can you also help me with my problem? Note: I was tasked to use... (4 Replies)
Discussion started by: akopocpoypoy
4 Replies

2. Shell Programming and Scripting

Adding the squence numbers

Hi All, Could you please help me on this requirement. File data: A A A B B B i need the output like A1 A2 A3 B1 (3 Replies)
Discussion started by: bmk123
3 Replies

3. Shell Programming and Scripting

Shell Scripting Date manipulation

Hi Experts, i have date as inputdate=01/01/2013,how to get the previous date from this date and also first day's date of the month. example: inputdate=01/06/2013 previousdate=31/05/2013 firstdate=01/05/2013 how can i get solution to this. my unix is not supporting GNU Dates ... (0 Replies)
Discussion started by: learner24
0 Replies

4. Shell Programming and Scripting

Data manipulation using shell

Dear all I have a dataset (in text format,delimited by tab) which have 100 variables (say, var0-var99) and more than 100,000 observations. I want to do the following: 1. for variable var0-var49, I want to add "00" in front of each data (for example, "1" would become "001") 2. for variable... (8 Replies)
Discussion started by: littlewenwen
8 Replies

5. Shell Programming and Scripting

Help with number field manipulation

I have a comma separated file containing numbers, I would like to read the file and divide each number by 1024 and create an output file. Input file : 50312.00,3434.05, ,3433.34,124344.00,434343.00, , , Output file: 49.13,3.35,3.35,0,12.05,424.16,0,0 Please click this link: How to... (2 Replies)
Discussion started by: inditopgun
2 Replies

6. Shell Programming and Scripting

Line number based manipulation

Hi I have a case where I am grabbing patterns and subsequent lines using sed -n -e '/regex/{$!N;p;}' This returns just the regex line when it is the last line of my file. Now I may have even number of lines in some cases (regex never at end) and odd in very rare cases. If the line... (6 Replies)
Discussion started by: jamie_123
6 Replies

7. UNIX for Dummies Questions & Answers

Finding numbers in lines with strings and number and doing some manipulation

Hi, I want to write a script that does something like this: I have a file, in which in every line, there is a string of words, and followed by some space, a number. Now, I want to identify the line, which has the largest startFace number (say m=8118), take that number and add it to the... (2 Replies)
Discussion started by: super_commando
2 Replies

8. UNIX for Advanced & Expert Users

string manipulation in bash shell

Hi All, I am using a bash shell and want to the following thing. A process sends the following string to my script BACKUP_FAIL_REASON="Failed - Application Dump CDMACA-0:grep: /opt/nortel/ca/data/1245184/sd00/image1/S110907070708HIS... (4 Replies)
Discussion started by: Pkumar Sachin
4 Replies

9. Shell Programming and Scripting

Time Manipulation in shell script

Hi all, I have a script that requires time comparisons and sending out an email alert only if the specified interval has been completed. The script runs in Cron tab every 5 mins. For ex: If the interval is set to 2 hrs (Dynamic & varies ) My script should execute and if it finds any error... (1 Reply)
Discussion started by: praseecg
1 Replies

10. Shell Programming and Scripting

Manipulation of Date in Shell

Reuirement: I have a set of files ina diectory which has the name in format "WWW-YYYYmmDD" like, WWW-20070226. for 26th FEB 2007. Now I need to write a shell script which should move the files to directory named "old" in the same directory if date attached to file is 90 days prior to today's... (1 Reply)
Discussion started by: jnanesh.b
1 Replies
Login or Register to Ask a Question