inserting line at particular linenumber using sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting inserting line at particular linenumber using sed
# 1  
Old 06-08-2011
inserting line at particular linenumber using sed

Could anyone tell me how to insert a line at a particular line number using sed.
sed '2i\newtext' filename

I have tried the above command .But it is not working. I am using tcsh shell .Please help.

Moderator's Comments:
Mod Comment Double post, continued here
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Inserting new line

Hi all, I want ot print a header with new line in the end. I am using echo like echo "this is header" I want output like This is header $ I tried -e also but it's not working. echo - e Can anyone help please? (6 Replies)
Discussion started by: dsa
6 Replies

2. 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

3. Shell Programming and Scripting

Inserting text with SED

Hi guys, I need to insert @test.com after each entry in my .txt file. 1 2 3 4 1@test.com 2@test.com 3@test.com 4@test.com Tried to use cat test.txt |sed 's/$/@test.com/'but it does this instead: 1 @test.com 2 (6 Replies)
Discussion started by: spirm8
6 Replies

4. Shell Programming and Scripting

Help with inserting a line

Hello, I am new to this forum. I have a question in Unix shell scripting. Here is my requirement I have 1000 files and I need to insert a header with one line at the top of each of the 1000 files. Please let me know if you have any solution for this Thanks in advance. Raj (4 Replies)
Discussion started by: trajashekar
4 Replies

5. Shell Programming and Scripting

Inserting a line in a file after every alternate line

Friends , I have a large file and i need to insert a line after every line.I am actually unaware how to do it.Any help appreciated. My File control station *ATM* , qread $OSS.Jul13A.FI01 interval 1 intcount 1 control station *ATM* , qread $OSS.Jul13A.FI02 interval 1 intcount... (4 Replies)
Discussion started by: appu2176
4 Replies

6. Shell Programming and Scripting

problem with sed for inserting command

Hello, i use sed '/good/ a\INSERT' 1.txt command for insert a text on my file on linux butit does not work see the output : # sed '/good/ a\INSERT' 1.txt if_test=iso ifup=eth0 Hello World Bye now good INSERT # cat 1.txt if_test=iso ifup=eth0 Hello World Bye now (1 Reply)
Discussion started by: blackmetal
1 Replies

7. UNIX for Advanced & Expert Users

Inserting a line before the line which matches the patter

Hi Is there any command where we can insert a line "2|||" before every line starting with "3|" my input is as follows 1|ETG|12345 3|79.58|||GBP|| 1|ETG|12345 3|79.58|||GBP|| 1|ETG|12345 2|EN_GB||Electrogalvanize 0.5 m2 ( Renault ) 1|ETG|12345 3|88.51|||GBP|| desired output... (10 Replies)
Discussion started by: laxmi131
10 Replies

8. Shell Programming and Scripting

Inserting a new line

I have a file where each line starts with a "update" statement. I want to insert a new line, after each line, with the words "go" in the new line. Can someone help me out with this? (1 Reply)
Discussion started by: ssmallya
1 Replies

9. Shell Programming and Scripting

Inserting New Line in File using Sed ??

Dear All, I have a file called football where i have a list of 11 players each on different lines. I wish to add a name of another player on the first line. I have created a file called footballscript in vi writing the following sed command to achieve this ... cat football | sed -e '1 i\... (4 Replies)
Discussion started by: Mary_xxx
4 Replies

10. UNIX for Dummies Questions & Answers

inserting line??

guys can anyone tel me how to insert a line in a file(bash) using line number i wanna insert the line using LINE NUMBER...i know for inserting above or below a perticular line we can use sed a\ or i\.... thanks in advance.... (7 Replies)
Discussion started by: anj
7 Replies
Login or Register to Ask a Question
PYP(1)							      General Commands Manual							    PYP(1)

NAME
pyp - The Pyed Piper: A Modern Python Alternative to awk, sed and Other Unix Text Manipulation Utilities SYNOPSIS
pyp [options] files ... DESCRIPTION
pyp, the Pyed Piper, is a command line tool for text manipulation. It is similar to awk and sed in functionality, but its subcommands are Python based, and thus more familiar to many programmers. It can operate both on a per-line base and on the complete input stream. Different features can be pipelined in a single command by using the pipe character familiar from shell commands. pyp backs up its input for reruns with modified commands, and can save commands as macros. On the downside, the rerun feature makes it unsuitable for continuous pipe operation. OPTIONS
These programs follow the usual GNU command line syntax, with long options starting with two dashes (`-'). A summary of options is included below. For a complete description, use --manual. -h, --help Show this help message and exit. -m, --manual Prints out extended help. -l, --macro_list Lists all available macros. -s MACRO_SAVE_NAME, --macro_save=MACRO_SAVE_NAME Saves current command as macro. use "#" for adding comments EXAMPLE: pyp -s "great_macro # prints first letter" "p[1]". -f MACRO_FIND_NAME, --macro_find=MACRO_FIND_NAME Searches for macros with keyword or user name. -d MACRO_DELETE_NAME, --macro_delete=MACRO_DELETE_NAME Deletes specified public macro. -g, --macro_group Specify group macros for save and delete; default is user. -t TEXT_FILE, --text_file=TEXT_FILE Specify text file to load. For advanced users, you should typically cat a file into pyp. -x, --execute Execute all commands. -c, --turn_off_color Prints raw, uncolored output. -u, --unmodified_config Prints out generic PypCustom.py config file. -b BLANK_INPUTS, --blank_inputs=BLANK_INPUTS Generate this number of blank input lines; useful for generating numbered lists with variable 'n'. -n, --no_input Use with command that generates output with no input; same as --dummy_input 1. -k, --keep_false Print blank lines for lines that test as False. default is to filter out False lines from the output. -r, --rerun Rerun based on automatically cached data from the last run. Use this after executing "pyp", pasting input into the shell, and hitting CTRL-D. SEE ALSO
awk(1), grep(1), sed(1). AUTHOR
pyp was written by Toby Rosen <tobyrosen@gmail.com>. This manual page was written by Khalid El Fathi <khalid@elfathi.fr>, for the Debian project (and may be used by others). March 19, 2012 PYP(1)