Editing all files inside folders and updating pos 88-94 with continuous numbering.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Editing all files inside folders and updating pos 88-94 with continuous numbering.
# 1  
Old 12-10-2012
Editing all files inside folders and updating pos 88-94 with continuous numbering.

Here is expected output:-
For each file with following file name pattern we need to look at position 1 inside first file matching our search criteria if first letter of the line is 5 then position 88-94 will be 0000001 then look for line immediately after 5 which starts with i.e. position 1 = 8 then position 88-94 will be 0000001 for that line starting with 8. Now again look first line start with 5, if matches then set position 88-94 will be 0000002. Now again look for line starting with 8 and set position 88-94 will be 0000002. Process this untill end of First file. Now assume last occurrence of line starting with 8 have position 88-94 = 0000010 then Look for occurrence of 5 in position 1 inside Second file If found then set position 88-94 will be 0000011, Also find line staring with 8 immediately and set position 88-94 will be 0000011.Continue numbering this until we are done with file matching our file search criteria.
Expected Output:-
File 1 name = ABCDEFG1234567_mm-dd-yy_hh_mm_ss123.data
Code:
Position:-      1234567890..............................................94
                101 101000048 CITY        ABCDEF FILE BC TOMJE                                    
                5220ABCDEF PQRSTUVWX   2342342345PPDAB            0000001
                101 101000048 CITY        ABCDEF FILE BC TOMJE        12
                8220000005005550001000000000000                   0000001
                5225ABCDEF PQRSTUVWX 121029080319303110           0000002 
                11 101000048 CITY        ABCDEF FILE BC TOMJE        13
                820000005005550001000000000000                    0000002 

File 2 name = ABCDEFG1234567_mm-dd-yy_hh_mm_ss145.data
Code:
Position:-      1234567890..............................................94
                101 101000048 CITY        ABCDEF FILE BC TOMJE                                    
                5220ABCDEF PQRSTUVWX   2342342345PPDAB            0000003
                101 101000048 CITY        ABCDEF FILE BC TOMJE        12
                8220000005005550001000000000000                   0000003
                5225ABCDEF PQRSTUVWX 121029080319303110           0000004 
                11 101000048 CITY        ABCDEF FILE BC TOMJE        13
                820000005005550001000000000000                    0000004 

File 3 name = ABCDEFG1234567_mm-dd-yy_hh_mm_ss167.data
Code:
Position:-      1234567890..............................................94
                101 101000048 CITY        ABCDEF FILE BC TOMJE                                    
                5220ABCDEF PQRSTUVWX   2342342345PPDAB            0000005
                101 101000048 CITY        ABCDEF FILE BC TOMJE        12
                8220000005005550001000000000000                   0000005
                5225ABCDEF PQRSTUVWX 121029080319303110           0000006 
                11 101000048 CITY        ABCDEF FILE BC TOMJE        13
                820000005005550001000000000000                    0000006 

File 4 name = ABCDEFG1234567_mm-dd-yy_hh_mm_ss189.data
Code:
Position:-      1234567890..............................................94
                101 101000048 CITY        ABCDEF FILE BC TOMJE                                    
                5220ABCDEF PQRSTUVWX   2342342345PPDAB            0000007
                101 101000048 CITY        ABCDEF FILE BC TOMJE        12
                8220000005005550001000000000000                   0000007
                5225ABCDEF PQRSTUVWX 121029080319303110           0000008 
                11 101000048 CITY        ABCDEF FILE BC TOMJE        13
                820000005005550001000000000000                    0000008

Here is the Code which find the files matching criteria:-
Code:
TS=`date +"%m-%d-%Y"`| for fname in `find . -name "ABCJmdmfbsjop???????_${TS}*.data"`
do    # Matching File Processing Code.


Last edited by lancesunny; 12-11-2012 at 05:56 PM..
# 2  
Old 12-10-2012
Show the input you have and the output you want, please.
# 3  
Old 12-10-2012
Just now I've updated four files which are there is that folder. I need to update these files with above criteria.
Thanks,
-Lance
# 4  
Old 12-10-2012
That's the input you want, now show the output you want.
# 5  
Old 12-10-2012
Here is expected output:-
For each file with following file name pattern we need to look at position 1 inside first file matching our search criteria if first letter of the line is 5 then position 88-94 will be 0000001 then look for line immediately after 5 which starts with i.e. position 1 = 8 then position 88-94 will be 0000001 for that line starting with 8. Now again look first line start with 5, if matches then set position 88-94 will be 0000002. Now again look for line starting with 8 and set position 88-94 will be 0000002. Process this untill end of First file. Now assume last occurrence of line starting with 8 have position 88-94 = 0000010 then Look for occurrence of 5 in position 1 inside Second file If found then set position 88-94 will be 0000011, Also find line staring with 8 immediately and set position 88-94 will be 0000011.Continue numbering this until we are done with file matching our file search criteria.

File 1 name = ABCDEFG1234567_mm-dd-yy_hh_mm_ss123.data
Code:
Position:-      1234567890..............................................94
                101 101000048 CITY        ABCDEF FILE BC TOMJE                                    
                5220ABCDEF PQRSTUVWX   2342342345PPDAB            0000001
                101 101000048 CITY        ABCDEF FILE BC TOMJE        12
                8220000005005550001000000000000                   0000001
                5225ABCDEF PQRSTUVWX 121029080319303110           0000002 
                11 101000048 CITY        ABCDEF FILE BC TOMJE        13
                820000005005550001000000000000                    0000002 

File 2 name = ABCDEFG1234567_mm-dd-yy_hh_mm_ss145.data
Code:
Position:-      1234567890..............................................94
                101 101000048 CITY        ABCDEF FILE BC TOMJE                                    
                5220ABCDEF PQRSTUVWX   2342342345PPDAB            0000003
                101 101000048 CITY        ABCDEF FILE BC TOMJE        12
                8220000005005550001000000000000                   0000003
                5225ABCDEF PQRSTUVWX 121029080319303110           0000004 
                11 101000048 CITY        ABCDEF FILE BC TOMJE        13
                820000005005550001000000000000                    0000004 

File 3 name = ABCDEFG1234567_mm-dd-yy_hh_mm_ss167.data
Code:
Position:-      1234567890..............................................94
                101 101000048 CITY        ABCDEF FILE BC TOMJE                                    
                5220ABCDEF PQRSTUVWX   2342342345PPDAB            0000005
                101 101000048 CITY        ABCDEF FILE BC TOMJE        12
                8220000005005550001000000000000                   0000005
                5225ABCDEF PQRSTUVWX 121029080319303110           0000006 
                11 101000048 CITY        ABCDEF FILE BC TOMJE        13
                820000005005550001000000000000                    0000006 

File 4 name = ABCDEFG1234567_mm-dd-yy_hh_mm_ss189.data
Code:
Position:-      1234567890..............................................94
                101 101000048 CITY        ABCDEF FILE BC TOMJE                                    
                5220ABCDEF PQRSTUVWX   2342342345PPDAB            0000007
                101 101000048 CITY        ABCDEF FILE BC TOMJE        12
                8220000005005550001000000000000                   0000007
                5225ABCDEF PQRSTUVWX 121029080319303110           0000008 
                11 101000048 CITY        ABCDEF FILE BC TOMJE        13
                820000005005550001000000000000                    0000008

Here is the Code which find the files matching criteria:-
Code:
TS=`date +"%m-%d-%Y"`| for fname in `find . -name "ABCJmdmfbsjop???????_${TS}*.data"`
do    # Matching File Processing Code.


Last edited by lancesunny; 12-10-2012 at 11:35 PM..
# 6  
Old 12-11-2012
Your input and output data is missing a whole lot of columns. It also contains two leading tabs which may or may not actually be part of your data -- quite unclear. If I make a program that works with your 'data', it is guaranteed to not work for you.

This is probably why you've gotten so few replies.

Is this more like what your data actually looks like? (exclude the first line)
Code:
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234
101 101000048 CITY        ABCDEF FILE BC TOMJE
5220ABCDEF PQRSTUVWX   2342342345PPDAB                                                 0000001
101 101000048 CITY        ABCDEF FILE BC TOMJE                                             12
8220000005005550001000000000000                                                        0000001
5225ABCDEF PQRSTUVWX 121029080319303110                                                0000002
11 101000048 CITY        ABCDEF FILE BC TOMJE                                             13
820000005005550001000000000000                                                         0000002

Also, do you realize that your file-finding code will not find these files in any particular order? It will be arbitrarily determined by which is found first in the filesystem, not by their filenames.

Last edited by Corona688; 12-11-2012 at 01:14 PM..
# 7  
Old 12-11-2012
I am processing input files which consist of 94 characters per line.
Your representation of input file data is correct. Every file consists of 94 characters per line.File name = ABCDEFG1234567_mm-dd-yy_hh_mm_ss123.data.
I agree my file finding code will select file based on arbitrarily determined by which is found first in the file system. I think that code can be modified to find file based on date and early HH:MM:SS time present in file.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Uncompress several tar.gz files inside several folders

Hi, I need to uncompress sevral tar.gz files that are located insides sevral folders using a shell script. Folder tree looks like this : /folder/001 /folder/002 /folder/003 Inside each folder dossier (001,002,003) we can find 1 or several tar.gz files. I've scripted something... (9 Replies)
Discussion started by: shellX
9 Replies

2. Shell Programming and Scripting

How to copy files/folders and show the files/folders?

Hi, So i know we use cp -r as a basic to copy folders/files. I would like this BUT i would like to show the output of the files being copied. With the amazing knowledge i have i have gone as far as this: 1) find source/* -exec cp -r {} target/ \; 2) for ObjectToBeCopied in `find... (6 Replies)
Discussion started by: Imre
6 Replies

3. Shell Programming and Scripting

How to delete all the files and folders inside all the directories except some specific directory?

hi, i have a requirement to delete all the files from all the directories except some specific directories like archive and log. for example: there are following directories such as A B C D Archive E Log F which contains some sub directories and files. The requirement is to delete all the... (7 Replies)
Discussion started by: Little
7 Replies

4. Shell Programming and Scripting

Selective position file editing inside folder

I need to process 4 files having name pattern as followis:- 1) Each file starts with = ABCJmdmfbsjop letters + 7 Digit Number _mm-dd-yyyy-hh-mm-ss-3 Digit Number.data where ABCJmdmfbsjop :- is alphabet. Each file starts with this ABCJmdmfbsjop alphabet. 7 Digit Number :- Numeric 7 digits. __:-... (1 Reply)
Discussion started by: lancesunny
1 Replies

5. Shell Programming and Scripting

Check Character matching from pos 7-15 to pos 211-219 if True then replace 211-219 with spaces

Script for if characters from positions 7-15 are matching with characters from position 211-219 then replace all char from 211-219 with 9 space. Total length of record is 420. Here is the specification of the data in file. Position Field Data Type... (5 Replies)
Discussion started by: lancesunny
5 Replies

6. Shell Programming and Scripting

Listing folders that have a file inside them

Hi guys, I'm new to the forums and putting my foot in the door with SED and AWK. I was wondering if someone could help me as I think I'm making this harder than it needs to be... I have a list of folders named as urls, inside these are log files and possibly a 'status' file. I'm trying to get... (6 Replies)
Discussion started by: KakersUK
6 Replies

7. Shell Programming and Scripting

Need help in updating the tables inside shell script

I have an input file with contents like : 1LMXTJJD0W28TX2 1LS1XJGDEVWAC5T 1LK81JVDE2HRNDG 1LMXTJJD0W28TX2 1LS1XJGDEVWAC5T 1LK81JVDE2HRNDG 1LMXTJJD0W28TX2 I need to read each field from the file pass it to a query: select count(*) from usage_error where usage_id='$field... (17 Replies)
Discussion started by: Rajesh Putnala
17 Replies

8. UNIX for Dummies Questions & Answers

Searching for folders/parent folders not files.

Hello again, A little while back I got help with creating a command to search all directories and sub directories for files from daystart of day x. I'm wondering if there is a command that I've overlooked that may be able to search for / write folder names to an output file which ideally... (2 Replies)
Discussion started by: Aussiemick
2 Replies

9. Shell Programming and Scripting

Rename files with continuous numbers

I have a huge collection of HTML files. They have their own file names with htmlextension. I want to rename each of these files with continuous numbers starting from 1.html till the last count of files. Simply it means that if there are three files like this abc.html cdfhg.html rmbd.htmlthen... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

10. Shell Programming and Scripting

for loop, calling and editing multiple files inside

hey guys, I'm trying to call and modify multiple files inside the for loop, i can't get it to work... ------------------------ AFILE=/dir/a_file.txt BFILE=/dir/b_file.txt CFILE=/dir/c_file.txt ADESTFILE=/dir/a_dest_file.txt BDESTFILE=/dir/b_dest_file.txt... (6 Replies)
Discussion started by: DeuceLee
6 Replies
Login or Register to Ask a Question