Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help needed on file handling scripts

Status
Not open for further replies.

poolban

Programmer
Aug 12, 2000
9
SG
Hello,<br>I have a file in UNIX as(let us say name is a.txt)and the content is like:<br><br>header<br>12345678901234567890<br>12345678901234567890<br>12345678901234567890<br>trailer<br><br>I want to have a file b.txt which will look like<br><br>12345678901234567890********************<br>12345678901234567890********************<br>12345678901234567890********************<br><br>This means I want to put some fixed number of * at the end of each line and I want to remove the header and trailer record. The header (record number 1) and trailer record (last record) can have any content and unconditionally I want them to be removed from the target file.<br><br>One small point. Let us assume I know that the original file (a.txt) has record length of 20. The final file record length also I know (assume 110). In this case, the script should calculate (110 - 90) and generate 90 (110 - 20) * (or any character for that matter - may be space) as filler. The value 110 and 20 can be stored in variables in the script program.<br><br>The number of records between 'header' and 'trailer' is unknown in real life file.<br><br>Please provide me a script which can be used as convert &lt;file-name&gt; which will take file name as a.txt and will convert that as a.txt.conv<br><br>Best regards,<br><br>Poolak
 
sed '1d;s/[^$]$/&\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/;$d' < infile > workfile
cut -b-120 workfile > outfile
rm workfile


Deltes the 1st line, adds 120 * to each line, deletes the last line then take the first 120 chars of each line. [sig]<p>Ged Jones<br><a href=mailto:gedejones@hotmail.com>gedejones@hotmail.com</a><br><a href= > </a><br>Top man[/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top