Sponsored Content
Top Forums Shell Programming and Scripting Inserting a line when its length is variable Post 302361016 by nxp on Monday 12th of October 2009 01:47:19 AM
Old 10-12-2009
Inserting a line when its length is variable

Hi Unix experts

I have simple text files in which the number of lines vary from one file to another. They look like the following:
 34    46 
 76    72
 39    68

I want to grab the first number of the last line of each file (let's say A= 39 in the above example), which is always a multiplication of 3, and insert a new line in the 28th line of another text file with the following format:

0, (A/3) +1, 0, 3,6,9,12,15,...,A

Where A can be a number between 3 and 54, so the number of fields in the line would be variable. Positions of zeros(0) in the line remain fixed. In case of A=39 the line lools like:

0, 14, 0,3,6,9,12,15,18,21,24,27,30,33,36,39

Any help is very much appreciated.


10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

creating a fixed length output from a variable length input

Is there a command that sets a variable length? I have a input of a variable length field but my output for that field needs to be set to 32 char. Is there such a command? I am on a sun box running ksh Thanks (2 Replies)
Discussion started by: r1500
2 Replies

2. UNIX for Dummies Questions & Answers

Convert a tab delimited/variable length file to fixed length file

Hi, all. I need to convert a file tab delimited/variable length file in AIX to a fixed lenght file delimited by spaces. This is the input file: 10200002<tab>US$ COM<tab>16/12/2008<tab>2,3775<tab>2,3783 19300978<tab>EURO<tab>16/12/2008<tab>3,28523<tab>3,28657 And this is the expected... (2 Replies)
Discussion started by: Everton_Silveir
2 Replies

3. Shell Programming and Scripting

Make variable length record a fixed length

Very, very new to unix scripting and have a unique situation. I have a file of records that contain 3 records types: (H)eader Records (D)etail Records (T)railer Records The Detail records are 82 bytes in length which is perfect. The Header and Trailer records sometimes are 82 bytes in... (3 Replies)
Discussion started by: jclanc8
3 Replies

4. Shell Programming and Scripting

changing a variable length text to a fixed length

Hi, Can anyone help with a effective solution ? I need to change a variable length text field (between 1 - 18 characters) to a fixed length text of 18 characters with the unused portion, at the end, filled with spaces. The text field is actually field 10 of a .csv file however I could cut... (7 Replies)
Discussion started by: dc18
7 Replies

5. Shell Programming and Scripting

inserting a variable to a new line

In my script I am using sed to insert a line. Suppose I have a variable called ck_size=5 and a temporary file called tmp I want to add a certain line in the tmp file .Please see the below command sed -i '2a\maitee is $ck_size' /dun/homes/lrsprod/tmp I want in 2 line of tmp file... (7 Replies)
Discussion started by: maitree
7 Replies

6. UNIX for Dummies Questions & Answers

print variable length text from the middle of a line?

I am trying to get text from a webpage, in terminal form. So far I am: 1. getting the html for the page printed using curl (curl -s webpage.com), which is then 2. piped to awk, printing line number 29 (awk NR==29), then 3. this is where I am sort of lost. I know where in the printed line I... (7 Replies)
Discussion started by: darkfalz
7 Replies

7. Shell Programming and Scripting

Check for length which exceeds specified length in a line

Hi, I have a issue, I need to loop through a comma delimited file and check for the length which exceeds specified length , if Yes truncate the string. But my problem is , I do not have to check for all the fields and the field lenght is not same for all the fields. For ex: Say my line... (9 Replies)
Discussion started by: rashmisb
9 Replies

8. Shell Programming and Scripting

Commenting a specific line and inserting a new line after commented line.

Hello All, I have following file contents cat file #line=aaaaaa #line=bbbbbb #line=cccccc #line=dddddd line=eeeeee #comment=11111 #comment=22222 #comment=33333 #comment=44444 comment=55555 Testing script Good Luck! I would like to comment line line=eeeeee and insert a new line... (19 Replies)
Discussion started by: manishdivs
19 Replies

9. UNIX for Dummies Questions & Answers

Help with awk, where line length and field position are variable

I have several questions about using awk. I'm hoping someone could lend me a hand. (I'm also hoping that my questions make sense.) I have a file that contains pipe separated data. Each line has similar data but the number of fields and the field position on each line is variable. ... (3 Replies)
Discussion started by: Cheese64
3 Replies

10. Shell Programming and Scripting

Convert variable length record to fixed length

Hi Team, I have an issue to split the file which is having special chracter(German Char) using awk command. I have a different length records in a file. I am separating the files based on the length using awk command. The command is working fine if the record is not having any... (7 Replies)
Discussion started by: Anthuvan
7 Replies
DtEditorGoToLine(library call)											    DtEditorGoToLine(library call)

DtEditorGoToLine -- move the insert cursor for a DtEditor widget to a specified line SYNOPSIS
#include <Dt/Editor.h> void DtEditorGoToLine( Widget widget, int lineNumber); DESCRIPTION
The DtEditorGoToLine function moves the insert cursor for the DtEditor widget to the beginning of the line specified by the lineNumber argument. The cursor can be moved to the last line by specifying DtEDITOR_LAST_LINE as the line number. If the line is not currently on- screen, the contents for the DtEditor widget are scrolled to display the new insertion position. The lineNumber argument is the number of the line in the file, counting from 1. If the lineNumber argument is less than 1, the insert cur- sor is placed at the beginning of the first line. If the argument is greater than the total number of lines, the cursor is placed at the last line of text. The insert cursor can be moved to a specific character position with DtEditorSetInsertionPosition(3). The DtNtopCharacter resource can be used to control which line is displayed at the top of the DtEditor widget. The widget argument specifies the DtEditor widget ID. The lineNumber argument specifies the line number within the DtEditor widget. For a complete definition of the DtEditor widget and its associated resources, see DtEditor(3). RETURN VALUE
The DtEditorGoToLine function returns no value. SEE ALSO
Dt/Editor.h - DtEditor(5), DtEditor(3), DtEditorSetInsertionPosition(3). DtEditorGoToLine(library call)

Featured Tech Videos

All times are GMT -4. The time now is 01:56 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy