Sponsored Content
Top Forums Shell Programming and Scripting Modify Specific Line of a Text File Post 302287044 by jim mcnamara on Thursday 12th of February 2009 03:00:12 PM
Old 02-12-2009
suppose you want to add "hi there" between lines 2 & 3
Code:
sed '3i\
hi there' oldfile > newfile

after the \ there must a be a new line
 

10 More Discussions You Might Find Interesting

1. Programming

jumping to a specific line in a text file

hi everybody! i need to read a specific line from a text file using C. can any one suggest how to do it. i m aware abt fread(), fwrite(), fseek()... but using these allows the pointer to be moved 1 character at a time. Is there a way i could jump directly to a line if i know the line number?... (4 Replies)
Discussion started by: mridula
4 Replies

2. Shell Programming and Scripting

Adding specific text and spaces to each line in a text file

Hi, I wanted to add specific text to each row in a text file containing three rows. Example: 0 8 7 6 5 5 7 8 9 0 7 9 7 8 9 0 1 2 And I want to add a 21 at the beginning of the first row, and blank spaces at the beginning of the second two rows. To get this: 21 0 8 7 6 5 5 7 8... (4 Replies)
Discussion started by: hertingm
4 Replies

3. Shell Programming and Scripting

Need help to modify perl script: Text file with line and more than 1 space

Dear Friends, I am beginner in Perl and trying to find the problem in a script. Kindly help me to modify the script. My script is not giving the output for the last field and followed text (LA: Language English). Input file & script as follows: Input file: Thu Mar 19 2:34:14 EDT 2009 STC... (3 Replies)
Discussion started by: srsahu75
3 Replies

4. Shell Programming and Scripting

Reading data from a specific line in a text file

hello, I have got the following problem that I am hoping someone can help with please. 1. I have got the following text file (below) , the columns data are 'Test Day', 'Board', 'Betting Number'. TEXT FILE ============================================ 1 3 02-01-27-28-29-30 0 1... (1 Reply)
Discussion started by: jermaine4ever
1 Replies

5. UNIX for Dummies Questions & Answers

Inputting text to a specific line of a file

Hi all, I have a script which uses a basic line to add text into another file e.g. grep -i test * >> test.txt Is there a way I can get the output of the grep to output to a specific line in the text.txt for example output above the line starting "Bottom line..." (6 Replies)
Discussion started by: JayC89
6 Replies

6. Linux

Get a specific line number from a text file

Hello! All, Could you please tell me how to get a specific line number from a text file? For example below, ABC DEF ---> Get this line number, return to an variable GHI My OS is Linux. Thank you so much for your help in advance! (3 Replies)
Discussion started by: barryxian
3 Replies

7. Shell Programming and Scripting

Update specific field in a line of text file

I have a text file like this: subject1:LecturerA:10 subject2:LecturerA:40 if I was given string in column 1 and 2 (which are subject 1 and LecturerA) , i need to update 3rd field of that line containing that given string , which is, number 10 need to be updated to 100 ,for example. The... (6 Replies)
Discussion started by: bmtoan
6 Replies

8. Shell Programming and Scripting

Modify one line in a plain text file

Hi everyone, I want to know, if there is a way to modify one line in a text file with unix script, with out re-writing all the file. For example, i have this file: CONFIGURATION_1=XXXX CONFIGURATION_2=YYYY CONFIGURATION_3=ZZZZ supose i have a command or function "modify" that... (7 Replies)
Discussion started by: Xedrox
7 Replies

9. Shell Programming and Scripting

Extract specific line in an html file starting and ending with specific pattern to a text file

Hi This is my first post and I'm just a beginner. So please be nice to me. I have a couple of html files where a pattern beginning with "http://www.site.com" and ending with "/resource.dat" is present on every 241st line. How do I extract this to a new text file? I have tried sed -n 241,241p... (13 Replies)
Discussion started by: dejavo
13 Replies

10. UNIX for Beginners Questions & Answers

Modify text file if found multiple pattern match for every line.

Looking for help, i have input file like below and want to modify to expected output, if can without create additional file, hope can direct modify it. have 2 thing need do. 1st is adding a word (testplan generation off) after ! ! IPG: Tue Aug 07 14:31:17 2018 2nd is adding... (16 Replies)
Discussion started by: kttan
16 Replies
erl_recomment(3erl)					     Erlang Module Definition					       erl_recomment(3erl)

NAME
erl_recomment - Inserting comments into abstract Erlang syntax trees. DESCRIPTION
Inserting comments into abstract Erlang syntax trees This module contains functions for inserting comments, described by position, indentation and text, as attachments on an abstract syntax tree, at the correct places. EXPORTS
quick_recomment_forms(Tree::Forms, Comments::[Comment]) -> syntaxTree() Types Forms = syntaxTree() | [syntaxTree()] Comment = {Line, Column, Indentation, Text} Line = integer() Column = integer() Indentation = integer() Text = [string()] Like recomment_forms/2 , but only inserts top-level comments. Comments within function definitions or declarations ("forms") are simply ignored. recomment_forms(Tree::Forms, Comments::[Comment]) -> syntaxTree() Types syntaxTree() (see module erl_syntax) Forms = syntaxTree() | [syntaxTree()] Comment = {Line, Column, Indentation, Text} Line = integer() Column = integer() Indentation = integer() Text = [string()] Attaches comments to the syntax tree/trees representing a program. The given Forms should be a single syntax tree of type form_list , or a list of syntax trees representing "program forms". The syntax trees must contain valid position information (for details, see recomment_tree/2 ). The result is a corresponding syntax tree of type form_list in which all comments in the list Comments have been attached at the proper places. Assuming Forms represents a program (or any sequence of "program forms"), any comments whose first lines are not directly associated with a specific program form will become standalone comments inserted between the neighbouring program forms. Furthermore, comments whose column position is less than or equal to one will not be attached to a program form that begins at a conflicting line number (this can happen with preprocessor-generated line -attributes). If Forms is a syntax tree of some other type than form_list , the comments will be inserted directly using recomment_tree/2 , and any comments left over from that process are added as postcomments on the result. Entries in Comments represent multi-line comments. For each entry, Line is the line number and Column the left column of the comment (the column of the first comment-introducing " % " character). Indentation is the number of character positions between the last non-whitespace character before the comment (or the left margin) and the left column of the comment. Text is a list of strings rep- resenting the consecutive comment lines in top-down order, where each string contains all characters following (but not including) the comment-introducing " % " and up to (but not including) the terminating newline. (Cf. module erl_comment_scan .) Evaluation exits with reason {bad_position, Pos} if the associated position information Pos of some subtree in the input does not have a recognizable format, or with reason {bad_tree, L, C} if insertion of a comment at line L , column C , fails because the tree structure is ill-formed. See also: erl_comment_scan , quick_recomment_forms/2 , recomment_tree/2 . recomment_tree(Tree::syntaxTree(), Comments::[Comment]) -> {syntaxTree(), [Comment]} Types Comment = {Line, Column, Indentation, Text} Line = integer() Column = integer() Indentation = integer() Text = [string()] Attaches comments to a syntax tree. The result is a pair {NewTree, Remainder} where NewTree is the given Tree where comments from the list Comments have been attached at the proper places. Remainder is the list of entries in Comments which have not been inserted, because their line numbers are greater than those of any node in the tree. The entries in Comments are inserted in order; if two comments become attached to the same node, they will appear in the same order in the program text. The nodes of the syntax tree must contain valid position information. This can be single integers, assumed to represent a line num- ber, or 2- or 3-tuples where the first or second element is an integer, in which case the leftmost integer element is assumed to represent the line number. Line numbers less than one are ignored (usually, the default line number for newly created nodes is zero). For details on the Line , Column and Indentation fields, and the behaviour in case of errors, see recomment_forms/2 . See also: recomment_forms/2 . AUTHORS
Richard Carlsson <richardc@it.uu.se > syntax_tools 1.6.7 erl_recomment(3erl)
All times are GMT -4. The time now is 08:20 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy