Scripting a global find and replace in an VME output print file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Scripting a global find and replace in an VME output print file
# 1  
Old 11-21-2012
Scripting a global find and replace in an VME output print file

Hi Folks,
Below is an extract from a VME Print file which gets handed over to a print house. The problem I have is not that tricky rther looking for a way to handle it in a simple and clean way.

Is to first select all lines with "0058" which have four spaces so "0058 " as the selcetion criteria. Only recodrs starting with 0058 and having a max length of 8 characters which the last 4 are spaces need be selected.

Once you have these replace the sapces with a code can be anything for 1 character plus 3 sapces to any combination up to 4 characters

Below is an example of the file it should be straight forward but the 0058 pattern can be found in other places in the file but shouldn't be selecetd

Any ideas and help gratefully accepted.

Gary

Code:
0042               ------------------------------------------------------
0058    
0072  558
0073  108       5060156962K                                        0.70

# 2  
Old 11-21-2012
Running through the file performing the following substitution should work.
Code:
perl -pi.bak -e 'BEGIN{$replacement="1 2 ";}s/^(0058) {4}$/$1$replacement/' source.vme

# 3  
Old 11-21-2012
Thnaks for the input, I was going down the awk route but like the Perl script looks quite clean
# 4  
Old 11-29-2012
Wrench

Hi all
I tried the perl but came up with something even simpler, but how to make this handle multiple files so for a given dircetory select all files and process each in turn cerating a new output file for each, any ideas?
Code:
sed 's/\(^0058*\)..../\1ABCD/' filename >new_filename

will replace 4 spaces with ABCD
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find and Replace in UNIX Scripting

Hi, Need your advices, Input : select code,status,input from VIEW1.VIEWNAME where IDU_CD IN ('S','N') and status_col='derived')) union select code,status,input from VIEW1.VIEWNAME2 where date='#p1' Expected output : select code,status,input from VIEW1.VIEWNAME where... (2 Replies)
Discussion started by: Nandy
2 Replies

2. Shell Programming and Scripting

Help with Passing the Output of grep to sed command - to find and replace a string in a file.

I have a file example.txt as follows :SomeTextGoesHere $$TODAY_DT=20140818 $$TODAY_DT=20140818 $$TODAY_DT=20140818I need to automatically update the date (20140818) in the above file, by getting the new date as argument, using a shell script. (It would even be better if I could pass... (5 Replies)
Discussion started by: SriRamKrish
5 Replies

3. Shell Programming and Scripting

Run a program-print parameters to output file-replace op file contents with max 4th col

Hi Friends, This is the only solution to my task. So, any help is highly appreciated. I have a file cat input1.bed chr1 100 200 abc chr1 120 300 def chr1 145 226 ghi chr2 567 600 unix Now, I have another file by name input2.bed (This file is a binary file not readable by the... (7 Replies)
Discussion started by: jacobs.smith
7 Replies

4. Shell Programming and Scripting

how to find files and replace them in a directory in Shell scripting

I have a directory /java/unix/data In data directory i have so many files from which i want to find some files who look alike below.(there are number of such below such files as well different files too in the data directory) -68395#svg.xml -56789#ghi.xml -67894#gjk.org -56734#gil.txt I... (6 Replies)
Discussion started by: pratima.kumari
6 Replies

5. Shell Programming and Scripting

Find in first column and replace the line with Awk, and output new file

Find in first column and replace the line with Awk, and output new file File1.txt"2011-11-02","Georgia","Atlanta","x","","" "2011-11-03","California","Los Angeles","x","","" "2011-11-04","Georgia","Atlanta","x","x","x" "2011-11-05","Georgia","Atlanta","x","x","" ... (4 Replies)
Discussion started by: charles33
4 Replies

6. Shell Programming and Scripting

Global search and replace multi line file

Hello I need to search for a mult-line strngs(with spaces in between and qoted) in a file1 and replace that text with Fixed string globally in file1. The strng to search for is in file2. The file is big with some 20K records. so speed and effciency is required file1: (where srch & rplc... (0 Replies)
Discussion started by: Hiano
0 Replies

7. Shell Programming and Scripting

Need help with scripting (find and replace)

Hello. I've got to files (source and target). 1) target.txt: .... #: tracopt/mimeview/php.py:97 msgid "" ... (1 Reply)
Discussion started by: Naar
1 Replies

8. Shell Programming and Scripting

Need an awk for a global find/replace in a file, specific column

I am new to unix and awk/sed etc... using C-Shell. Basically, I have a fixed length file that has 4 different record types on it, H, D, V, W all in column 1. I need to change all the W's in column 1 to D's. in the entire file. The W's can be anywhere in the file and must remain in the same... (3 Replies)
Discussion started by: jclanc8
3 Replies

9. UNIX for Dummies Questions & Answers

Find and replace in all files using shell scripting

Hi all, I'm looking to find and replace a string in all HTML files within a certain directory, including subdirectories. Normally, I would play with this a little to get it to work, but I can't mess this up, so I'm going to ask here. Basically, I want to find "<title>" in all *.htm* files... (11 Replies)
Discussion started by: slothario
11 Replies

10. UNIX for Dummies Questions & Answers

How to Find /replace and print?

Hi, I have one txt file, and I want replace 2 diffrent texts with somther text and the same time, I want to send that to print.. something like sed -e 's/Times-Roman/Helvetica/'|sed -e 's/Times/Helvetica/' oldfile > newfile < lp is this will workout? any idea? (1 Reply)
Discussion started by: redlotus72
1 Replies
Login or Register to Ask a Question