[bash help]Adding multiple lines of text into a specific spot into a text file
I am attempting to insert multiple lines of text into a specific place in a text file based on the lines above or below it.
For example, Here is a portion of a zone file.
I need to add 4 lines of MX records in between the final NS record and the first A record, and still leave 1 line of white space between each, so that it looks like this:
I've checked the other posts which have to do with inserting text into a file, and it seems like this can be done with some iteration of sed, but I'm not sure where to begin. the other examples of this kind of situation on this forum seemed to be dealing mostly with specific line numbers, or a static value to insert the line after. Where in this situation, the final NS record will change, and the amount of NS lines will change from zone file to zone file, so the only static value is the IN NS.
any help anyone can offer with this is greatly appriciated.
Suppose content of my first file:
first line
second line
third line
How can i insert text between "first line" & "second Iline"
Any help?????/ (7 Replies)
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)
I need to add "new lines" of text with special characters, to specific lines in the file. There are 3 modifications needed. Been testing 2 here without success.
#!/usr/bin/perl
use FileHandle;
$file=FileHandle->new;
$FILENAME="/opt/etc/usr/file.txt";
$file->open ("<$FILENAME") or die... (13 Replies)
this is Korn shell unix.
The scenario is I have a pipe delimited text file which needs to be customized. say for example,I have a pipe delimited text file with 15 columns(| delimited) and 200 rows. currently the 11th and 12th column has null values for all the records(there are other null columns... (4 Replies)
I have a space delimited text file with two columns. I would like to add NA to the first column of the text file.
Input:
19625 10.4791768259
19700 10.8146489183
19701 10.9084026759
19702 10.9861346978
19703 10.9304364984
Output:
NA19625 10.4791768259
NA19700 10.8146489183... (1 Reply)
I would like to use grep to select multiple lines from a text file using a single-column text file. Basically I want to only select lines from the first text file where the second column of the first text file matches the second text file. How do I go about doing that? Thanks! (5 Replies)
Hi,
I want to add a text to the end of the specific line in a file. Now my file looks like this:
999
111
222
333
111
444
I want to add the string " 555" to the end of the first line contaning 111. Moreover, I want to insert a newline after this line containg the "000" string. The... (8 Replies)
hello,
I try to add users from a text file with this form:
username:groupename:homedir
first i extract data which is separated by ":"
then i use useradd to add users/groups.
but,,, my code doesn't works :
#!/bin/bash
echo "give me a text file: "
read dir
# control if... (2 Replies)
This is an extract from a large file. The lines that start with fc are ports on a fabric switch. In between each fc port there is information about the port.
fc2/12 is up
Port description is SEIEDISCOVER-3
Speed is 4 Gbps
fc2/13 is down (Administratively down)
fc2/14 is up
Port... (1 Reply)
hi all,
trying this using shell/bash with sed/awk/grep
I have two files, one containing one column, the other containing multiple columns (comma delimited).
file1.txt
abc12345
def12345
ghi54321
...
file2.txt
abc1,text1,texta
abc,text2,textb
def123,text3,textc
gh,text4,textd... (6 Replies)
Discussion started by: shogun1970
6 Replies
LEARN ABOUT PHP
more
MORE(1) User Commands MORE(1)NAME
more - file perusal filter for crt viewing
SYNOPSIS
more [options] file...
DESCRIPTION
more is a filter for paging through text one screenful at a time. This version is especially primitive. Users should realize that less(1)
provides more(1) emulation plus extensive enhancements.
OPTIONS
Options are also taken from the environment variable MORE (make sure to precede them with a dash (-)) but command-line options will over-
ride those.
-d Prompt with "[Press space to continue, 'q' to quit.]", and display "[Press 'h' for instructions.]" instead of ringing the bell when
an illegal key is pressed.
-l Do not pause after any line containing a ^L (form feed).
-f Count logical lines, rather than screen lines (i.e., long lines are not folded).
-p Do not scroll. Instead, clear the whole screen and then display the text. Notice that this option is switched on automatically if
the executable is named page.
-c Do not scroll. Instead, paint each screen from the top, clearing the remainder of each line as it is displayed.
-s Squeeze multiple blank lines into one.
-u Suppress underlining.
-number
The screen size to use, in number of lines.
+number
Start displaying each file at line number.
+/string
The string to be searched in each file before starting to display it.
--help Display help text and exit.
-V, --version
Display version information and exit.
COMMANDS
Interactive commands for more are based on vi(1). Some commands may be preceded by a decimal number, called k in the descriptions below.
In the following descriptions, ^X means control-X.
h or ? Help; display a summary of these commands. If you forget all other commands, remember this one.
SPACE Display next k lines of text. Defaults to current screen size.
z Display next k lines of text. Defaults to current screen size. Argument becomes new default.
RETURN Display next k lines of text. Defaults to 1. Argument becomes new default.
d or ^D Scroll k lines. Default is current scroll size, initially 11. Argument becomes new default.
q or Q or INTERRUPT
Exit.
s Skip forward k lines of text. Defaults to 1.
f Skip forward k screenfuls of text. Defaults to 1.
b or ^B Skip backwards k screenfuls of text. Defaults to 1. Only works with files, not pipes.
' Go to the place where the last search started.
= Display current line number.
/pattern Search for kth occurrence of regular expression. Defaults to 1.
n Search for kth occurrence of last regular expression. Defaults to 1.
!command or :!command
Execute command in a subshell.
v Start up an editor at current line. The editor is taken from the environment variable VISUAL if defined, or EDITOR if
VISUAL is not defined, or defaults to vi if neither VISUAL nor EDITOR is defined.
^L Redraw screen.
:n Go to kth next file. Defaults to 1.
:p Go to kth previous file. Defaults to 1.
:f Display current file name and line number.
. Repeat previous command.
ENVIRONMENT
The more command respects the following environment variables, if they exist:
MORE This variable may be set with favored options to more.
SHELL Current shell in use (normally set by the shell at login time).
TERM The terminal type used by more to get the terminal characteristics necessary to manipulate the screen.
VISUAL The editor the user prefers. Invoked when command key v is pressed.
EDITOR The editor of choice when VISUAL is not specified.
SEE ALSO less(1), vi(1)AUTHORS
Eric Shienbrood, UC Berkeley
Modified by Geoff Peck, UCB to add underlining, single spacing
Modified by John Foderaro, UCB to add -c and MORE environment variable
HISTORY
The more command appeared in 3.0BSD. This man page documents more version 5.19 (Berkeley 6/29/88), which is currently in use in the Linux
community. Documentation was produced using several other versions of the man page, and extensive inspection of the source code.
AVAILABILITY
The more command is part of the util-linux package and is available from Linux Kernel Archive <https://www.kernel.org/pub/linux/utils/util-
linux/>.
util-linux February 2014 MORE(1)