![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| editing ELF file | tejuwala | Linux | 1 | 05-17-2008 08:22 PM |
| Editing file | rahul303 | Shell Programming and Scripting | 4 | 09-23-2007 07:49 PM |
| Editing File using awk/sed | Mohammed | Shell Programming and Scripting | 4 | 05-16-2007 08:00 AM |
| Editing the File using Awk | awk_beginner | Shell Programming and Scripting | 3 | 04-06-2007 07:43 AM |
| Help with editing file | dsravan | Shell Programming and Scripting | 4 | 01-31-2007 09:59 AM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Help editing a file
I have a data file which is a flat text file that has certain characters that are at the beginning of each line that identify it as being a certain type of data element. I want to write a small shell script that will take my data file and look at the beginning of certain lines and if it finds this certain line, then make a change to information that is located at different positions within the line. I know the exact positions of the data that I want to change. For example... I have lines that begin with the following:
AA0GAA11-030 or BA011BDSXH or CA0 or DA00100196800018184 where the AA0, or BA0, or CA0, or DA0 are the first three characters of the line that are constant. The data that follows later on within the line is a date 1902. I want to change the date from 1902 to 2002. So in essence I want to search my data file for lines that begin with AA0* or BA0* or CA0* or DA0* and once I encounter this pattern, I want to then look at a certain position in the line and change the data 1902 to 2002. Can anyone help with this? |
| Forum Sponsor | ||
|
|
|
|||
|
I tried using your suggestion, however, the date 1902 is not in a seperate field. It is embedded along with other data. For example:
AA0GAA11-030 ASY960000336ABDUL BARI MD 618 5TH AVENUE CAIRO GA31728 BARBARA GROOMS 229377709019020516053400 C00200 PROD This is one line in the data file. The line begins with AA0 and the date is actually further down in a string of numbers. Is there some "wild-card" that needs to be added so that it finds the 1902 within the string of data? |
|
|||
|
I tried it again as well on my origional data file and it doesn't change the date.....however.... it appears that when we post data on here that blank spaces and nulls are often removed so that the data string looks like one contiguous string. I copied and pasted the data that was in my origional post and yes indeed, the command worked as expected... just seems that when I run the command on my data file... that contains.. nulls and spaces... it doesn't work.. I will keep trying... thanks for your help.. if you think of something I'd appreciate your help alot.
|
|
|||
|
Good news... ! the command appears to be working correctly... however... if there is more than one instance of the date in each line.. it only changes the first date.. and skips any subsequent dates that might be later on in the data string for that particular line...
|
|||
| Google UNIX.COM |