Sponsored Content
Top Forums Shell Programming and Scripting How to insert text using a second file in Linux Post 302656619 by abhitanshu on Friday 15th of June 2012 04:44:04 AM
Old 06-15-2012
Code:
sed '3r file2' file1

This command is replacing the text.

But i want the text to be inserted.

Last edited by Scrutinizer; 06-15-2012 at 05:49 AM.. Reason: code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

insert text into top of file

how would you insert text into a existing file using aguments first arguments being the line of text and the second argument being file name (1 Reply)
Discussion started by: jimbob
1 Replies

2. Shell Programming and Scripting

insert some text to a file log

Hi experts, i have some problem with inserting text to a file, i have a file named test.log output like this : 11111 22222 33333 44444 55555 i want to insert date into the file test.log, expected output is : 20070501 11111 22222 33333 44444 55555 any idea? please help ... (4 Replies)
Discussion started by: bucci
4 Replies

3. Shell Programming and Scripting

insert text in the middle of a file

I want to insert a text into the middle of a file (3 Replies)
Discussion started by: relle
3 Replies

4. UNIX for Dummies Questions & Answers

How to insert text in the middle of a file

Hey guys, how do we take a line of text as an argument from a user and then insert it in the middle of a file irrespective of the number of lines in the file. I am trying to do this without SED or AWK. Inserting it in the beginning and at the end is easy, but i am trying to accomplish inserting... (6 Replies)
Discussion started by: kartikkumar84@g
6 Replies

5. Shell Programming and Scripting

How to insert some constant text at beginig of each line within a text file.

Dear Folks :), I am new to UNIX scripting and I do not know how can I insert some text in the first column of a UNIX text file at command promtp. I can do this in vi editor by using this command :g/^/s//BBB_ e,g I have a file named as Test.dat and it containins below text: michal... (4 Replies)
Discussion started by: Muhammad Afzal
4 Replies

6. Shell Programming and Scripting

Need to insert new text and change existing text in a file using SED

Hi all, I need to insert new text and change existing text in a file. For that I used the below line in the command line and got the expected output. sed '$a\ hi... ' shell > shell1 But I face problem when using the same in script. It is throwing the error as, sed: command garbled:... (4 Replies)
Discussion started by: iamgeethuj
4 Replies

7. Shell Programming and Scripting

Insert Text On file

Hi All, Can someone pls help me to insert some text on a file. my file contains something like below.. AKBULBU, BALUMIL, BATCH,BATCH BOARROB, BOTAKAT, C57896, CAKIOZE, CHECMER, CICOFRA, CISZPAW,2194485 I want output as USER_ID, LOGIN_ID (6 Replies)
Discussion started by: harshakusam
6 Replies

8. Shell Programming and Scripting

Insert text to file via ssh

I want to create a script that will set up key pairs from "thishost" to "remotehosts". I have a validate script in ~/<dir> that I need to prefix the generated key in the authorized_keys file, and I'm having to manually do this everytime. Here are my attemps, perhaps you could perfect them for... (3 Replies)
Discussion started by: ScannerDarkly
3 Replies

9. Shell Programming and Scripting

Insert value to db from text file

Hi, I have a single value in insertval file. I want to load that value to database with the current date. I tried the below code but it is inserting <NULL> to database and echo $c is also null. cat insertval | awk -F ' ' '{print $1}' > c echo c=$c data=`sqlplus -s user/pwd@hostname <<EOF ... (5 Replies)
Discussion started by: Neethu
5 Replies

10. Shell Programming and Scripting

How to insert text within a file?

Hi, I am trying to check for missing dates in a file and would want to insert the missing date into the file. Currently the script is as below #!/bin/ksh dates="dates" cat ${dates} | grep -v "^#" curr_month=`date '+%m` curr_day=`date '+%d` curr_year=`date '+%Y` #curr_month=02... (7 Replies)
Discussion started by: newbie_01
7 Replies
Mined  is a simple screen editor.  At any instant, a window of 24
lines is visible on the screen.  The current position in the file
is shown by the cursor.  Ordinary characters typed in are insert-
ed at the cursor.  Control characters and  keys  on  the  numeric
keypad	(at the right-hand side of the keyboard) are used to move
the cursor and perform other functions.  Commands exist  to  move
forward  and backward a word, and delete words either in front of
the cursor or behind it.  A word in this context is a sequence of
characters  delimited  on  both  ends by white space (space, tab,
line feed, start of file, or end  of  file).   The  commands  for
deleting  characters and words also work on line feeds, making it
possible to join two consecutive lines by deleting the line  feed
between  them.	 The  editor  maintains one save buffer (not dis-
played).  Commands are present to move text from the file to  the
buffer, from the buffer to the file, and to write the buffer onto
a new file.  If the edited text cannot be written out  due  to	a
full disk, it may still be possible to copy the whole text to the
save buffer and then write it to a different file on a	different
disk with CTRL-Q.  It may also be possible to escape from the ed-
itor with CTRL-S and remove some files.   Some	of  the  commands
prompt	for  arguments	(file names, search patterns, etc.).  All
commands that might result in  loss  of  the  file  being  edited
prompt to ask for confirmation.  A key (command or ordinary char-
acter) can be repeated times by typing where is the  escape  key.
Forward  and  backward searching requires a regular expression as
the search pattern.  Regular expressions follow the same rules as
in  the  editor,  These  rules	can be stated as: Any displayable
character matches itself.  . (period) matches any  character  ex-
cept line feed.  ^ (circumflex) matches the start of the line.	$
(dollar sign) matches the end of the line.  c matches the  char-
acter  c  (including  period, circumflex, etc).  [string] matches
any of the characters in the string.  [^string]  matches  any  of
the  characters  except  those	in the string.	[x-y] matches any
characters between x and y (e.g., [a-z]).  Pattern*  matches  any
number	of  occurrences of pattern.  Some examples of regular ex-
pressions are:
  The boy   matches the string The boy
  ^$	    matches any empty line.
  ^.$	    matches any line containing exactly 1 character
  ^A.*.$   matches any line starting with an A,  ending  with	a
	    period.
  ^[A-Z]*$  matches  any line containing only capital letters (or
	    empty).
  [A-Z0-9]  matches any line containing either a  capital  letter
	    or a digit.
  .*X$	    matches any line ending in X
  A.*B	    matches any line containing an A and then a B

Control characters cannot be entered into a file simply by typing
them because all of them are editor commands.  To enter a control
character,  depress  the ALT key, and then while holding it down,
hit the ESC key.  Release both ALT and ESC and type  the  control
character.   Control  characters  are displayed in reverse video.
The commands are as follows.

CURSOR MOTION
arrows Move the cursor in the indicated direction CTRL-A Move cursor to start of current line CTRL-Z Move cursor to end of current line CTRL-^ Move cursor to top of screen CTRL-_ Move cursor to end of screen CTRL-F Move cursor forward to start of next word CTRL-B Move cursor backward to start of previous word SCREEN MOTION
Home key Move to first character of the file End key Move to last character of the file PgUp key Scroll window up 23 lines (closer to start of the file) PgDn key Scroll window down 23 lines (closer to end of the file) CTRL-U Scroll window up 1 line CTRL-D Scroll window down 1 line MODIFYING TEXT
Del key Delete the character under the cursor Backspace Delete the character to left of the cursor CTRL-N Delete the next word CTRL-P Delete the previous word CTRL-T Delete tail of line (all characters from cursor to end of line) CTRL-O Open up the line (insert line feed and back up) CTRL-G Get and insert a file at the cursor position BUFFER OPERATIONS
CTRL-@ Set mark at current position for use with CTRL-C and CTRL-K CTRL-C Copy the text between the mark and the cursor into the buffer CTRL-K Delete text between mark and cursor; also copy it to the buffer CTRL-Y Yank contents of the buffer out and insert it at the cursor CTRL-Q Write the contents of the buffer onto a file MISCELLANEOUS
numeric + Search forward (prompts for regular expression) numeric - Search backward (prompts for regular expression) numeric 5 Display the file status CTRL-] Go to specific line CTRL-R Global replace pattern with string (from cursor to end) CTRL-L Line replace pattern with string CTRL-W Write the edited file back to the disk CTRL-X Exit the editor CTRL-S Fork off a shell (use CTRL-D to get back to the edi- tor) CTRL- Abort whatever the editor was doing and wait for com- mand CTRL-E Erase screen and redraw it CTRL-V Visit (edit) a new file Mined was designed by Andy Tanenbaum and written by Michiel Huis- jes.
All times are GMT -4. The time now is 10:33 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy