Name: Fouad Date: April 15, 2008 at 09:22:33 Pacific Subject: copy and past in a file OS: AIX 5.2 CPU/Ram: 4 / 8GB Model/Manufacturer: IBM
Comment:
Hi, My query is as follows: (1) I want to write a Schell Script which will first read files (file as variable).Each file contains multiple lines/records. (2) Each line /record in a file has a multiple characters (3) So I want a shell script - which will copy the CHARACTERS between the position 10 und 20 and past them in the position 40-50 of each line .
The file look ~ like that: line1:uTN02PS01AGC AUTO00129325 001293251400584180 55PRV0201 line2: TN02PS01AGC AUTO00129326 001293261400584180 55PRV0201 line3: uTN02PS01AGC AUTO00129327 001293271400584180 55PRV0201 ....and so on.
The caracters between positions 10 and 20 should be not eliminated but copied and pasted in the position 40-50 of each line.
I apreciate your help nails, I run the script you proposed but I do not see any difference between the original file and the new one(no change has been made). Any other suggestion?
I took your first like and placed it in datafile.txt.
Here's what the script does: if the length of the line is greater than 50 characters.
1) cut out characters 10 20 2) cut out characters 1 to 40 3) cut out characters 50 to the end of the line 4) glue together step 2), step 1), and step 3
The first line if yours and the second line is after the script runs. It looks correct to me:
you 're right the only thing to change is step 3): here must the line be cut from caracters 40 to the end of it. Now the script works fine. BTW: how can I define the input file as variable?
I don't know what you mean by "not saved in the same file", but here are two ways:
1) Since your script is not asking for any input, redirect your script as written to an output file. If your script is called myscript.ss, execute this:
myscript.ss filename > output.txt
2) Redirect the output of just the while loop by changing to this:
This script is a part off more larger script that those files checked, edit and transfer them to the database. Let say I have a folder /myfolder/unmfiles a lot off files with the ".unm" extention are saved there. I want that this script check every unm file, edit it in save it with the same name(redirect the output to the same file name). That means the input file name = output file name.
The shell doesn't allow editing files "in place" such as you've described. You'll have to rename the file once the loop completes such as this example:
The information on Computing.Net is the opinions of its users. Such
opinions may not be accurate and they are to be used at your own risk.
Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE