Sponsored Content
Top Forums Shell Programming and Scripting Incrementing parts of ten digits number by parts Post 302862315 by Natalie on Thursday 10th of October 2013 02:01:50 PM
Old 10-10-2013
Hello I am still working on my code..... The issue I faced is that i have to have 00 01 02 03 04 05 06 07 08 09 010 011 ...099 100. But my numbers are 1 2 3 4 5 ...How I can change it to different format? Moreover, my number is in the file....so basically it reads number in file compare and increment the number and rewrite file with new number Smilie But my piece of code gives me nothing lol Smilie

for example: file kuku.txt
cat kuku.txt
->2013081001
after running my code
cat kuku.txt
->2013081002


Code:
DIR="/Users/Natalie/1/kuku.txt"
n="Users/Natalie/1/$kuku.txt"
#echo "${n:0:4} ${n:4:2} ${n:6:2} ${n:8:2}"

fourthoct=${n:0:4}
thirdoct=${n:4:2}
secondoct=${n:6:2}
firstoct=${n:8:2}

if [ "$(ls -A $DIR)" ] then
sort /Users/Natalie/1/kuku.txt | tail -1 |

     while read firstoct secondoct thirdoct fourthoct
               do
            if [ $((++firstoct)) -eq 101 ]
                   then

                  firstoct=0
                   if [ $((++secondoct)) -eq 32 ]
                        then
 secondoct=0
                         if [ $((++thirdoct)) -eq 13 ]
                               then
                                thirdoct=0
                                   ((++fourthoct))
fi
fi
fi

echo $fourthoct$thirdoct$secondoct$firstoct >kuku.txt
done
else
echo "Hi its new file" >kuku.txt
fi


Last edited by Natalie; 10-10-2013 at 04:07 PM..
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

cksum parts of a file

Every time we build an executable the date and time are put into the file, I need to run checksum on just the working lines.(IE, no header files) Is this even possible, if so how would I go about it? I am using a HP-UX server any help you can give me will be greatly appreciated. Thanks (6 Replies)
Discussion started by: crazykelso
6 Replies

2. Shell Programming and Scripting

getting parts of a file

Hello, I'm trying to retreive certain bits of info from a file. the file contains a list like this info1:info2:info3:info4 info1:info2:info3:info4 info1:info2:info3:info4 info1:info2:info3:info4 how do i pick out only info2 or only info3 without the others? Thanks (11 Replies)
Discussion started by: bebop1111116
11 Replies

3. Shell Programming and Scripting

Extracting parts of a file.

Hello, I have a XML file as below and i would like to extract all the lines between <JOB & </JOB> for every such occurance. The number of lines between them is not fixed. Anyways to do this awk? ============ <JOB APR="1" AUG="1" DEC="1" FEB="1" JAN="1" JUL="1" JUN="1" MAR="1" MAY="1"... (3 Replies)
Discussion started by: srivat79
3 Replies

4. Shell Programming and Scripting

[ask]break line number into several parts

hlow all, i have file with wc -l file.txt is 3412112 line number so I want to break these files into several parts with assumsi line 1-1000000 will be create part1.txt and 1000001-2000000 will create part2.txt and 2000001-3000000 will create part3.txt and 3000001-3412112 will create... (5 Replies)
Discussion started by: zvtral
5 Replies

5. Shell Programming and Scripting

Parts is parts, but all together ...

I understand the individual pieces of the following (with one exception ..), but how does it all work as one? find ${HOME}/reports/ -name surveyresult*.txt -exec ls -1 {} \; | /usr/xpg4/bin/grep -E \ "${HOME}/reports/surveyresult{14,14}.txt" | sort > ${ResultsFileList} Find all files like... (1 Reply)
Discussion started by: jdorn001
1 Replies

6. Shell Programming and Scripting

Extract Parts of File

Hello All, I have a file like this Define schema flat_file_schema ( a varchar(20) ,b varchar(30) ,c varchar(40) ); (Insert into table ( a ,b ,c ) values ( 1 ,2 ,3 ); (4 Replies)
Discussion started by: nnani
4 Replies

7. Shell Programming and Scripting

Combine two parts of a file

Hello All, I have a file like this APPLY ( 'INSERT INTO brdcst_media_cntnt ( cntnt_id ,brdcst_media_cntnt_cd ,cntnt_prvdr_cd ,data_src_type_cd ,cntnt_titl_nm ,cntnt_desc ,batch_dt ,batch_id ) VALUES ( :cntnt_id (3 Replies)
Discussion started by: nnani
3 Replies

8. Shell Programming and Scripting

Getting various parts from the log

I am dealing with some app log, see example below: 22:16:13.601 ClientSession(905)--Connection(5)--SELECT GETDATE() 22:16:13.632 ClientSession(158)--Connection(5)--SELECT 1 22:16:13.632 ClientSession(848)--Connection(6735)--SELECT 1 So far I needed to collect certain column from it, such as... (3 Replies)
Discussion started by: migurus
3 Replies

9. Shell Programming and Scripting

How to get first four parts of the string?

I have the string: XXXX.YYYY_ZZZ.20180724.01.txt I need to get rid of .txt and get full four parts XXXX.YYYY_ZZZ.20180724.01 I did: CTL=`echo XXXX.YYYY_ZZZ.20180724.01.txt | rev | cut -d"." -f4 | rev` But got only YYYY_ZZZ What should I do to get all four parts of that... (4 Replies)
Discussion started by: digioleg54
4 Replies
All times are GMT -4. The time now is 08:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy