09-20-2010
sed to replace two lines with one
I want to use sed to check if a short line is contained in the line after it, and if it is, to delete the short one. In other words, the input is...
This is a
This is a line
... and I want it to give me...
This is a line
Here's what I've tried so far: s/\(^.*\)\n\(\1.*$\)/\2/
Also, is there a way to get sed to act directly on the input file, as opposed to a screen dump or creating an output file?
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
the file contains the follwoing lines
/*
* Copyright (C) 1995-1996 by XXX Corporation. This program
* contains proprietary and confidential information. All rights reserved
* except as may be permitted by prior written consent.
*
* $Id: xxx_err.h,v 1.10 2001/07/26 18:48:34 zzzz $
... (1 Reply)
Discussion started by: radha.kalivar
1 Replies
2. Shell Programming and Scripting
Hi,
I need a sed line that will find all lines that contain "<int key="NSWindowStyleMask">" and then replace the entire line (not just that one string) with "<int key="NSWindowStyleMask">8223</int>". It doesn't necessarily have to use sed as long as it gets the job done :)
Thanks (9 Replies)
Discussion started by: pcwiz
9 Replies
3. Shell Programming and Scripting
I am new to linux and would like to modify the contents of a file preferably using a one line. The situation is as follows
<start>
some lines
"I am the string"
"replace string"
more lines here
<end>
In the above example,On encountering "I am the string", the "replace string "should be... (6 Replies)
Discussion started by: supersimha
6 Replies
4. Shell Programming and Scripting
I have a file example.txt with content look like this:
<TAG>
1
2
3
</TAG>
and I use a sed command to replace everything between <TAG></TAG> as below:
sed -e 's/\(<TAG>\)*\(<.*\)/something/g' example.txt > example.txt.new
But unfortunately, the command failed to replace as i want, it... (23 Replies)
Discussion started by: dollylamb
23 Replies
5. Shell Programming and Scripting
Hi Everyone,
# cat 3
a
b
# cat 4
a
b
# perl -p -i -e "s/.*/c/ if $.==2" *
# cat 3
a
c
# cat 4
a
b (4 Replies)
Discussion started by: jimmy_y
4 Replies
6. Shell Programming and Scripting
i have something like this...
cat filename.txt
<complexType name="abc">
bklah vlah
blah
blha blha blah
blha
</complexType >
<complexType name="def">
bklah vlah
blah
blha blha blah
blha
</complexType >
.
.
.and so on.. its a very large file (11 Replies)
Discussion started by: vivek d r
11 Replies
7. Shell Programming and Scripting
Hi,
i want to replace
"Hi How
are You when
did you go to
delhi"
to
"Hi How
are you when
did you come from
delhi"
in a file.
Any idea how to do it? (2 Replies)
Discussion started by: abhitanshu
2 Replies
8. Shell Programming and Scripting
Hi All,
I have a input file as sample below
<this is not starting of file>
record
line1
line2
line3
end
line4
line5
record
line6
line7
line8
my requirement is this, i want to select a pattern between first record and end, whatever is written between first record and end.
and... (0 Replies)
Discussion started by: adgangwar
0 Replies
9. Shell Programming and Scripting
I am trying to find a line in a file ("Replace_Flag") and replace it with a variable which hold a multi lined file.
myVar=`cat myfile`
sed -e 's/Replace_Flag/'$myVar'/' /pathto/test.file
myfile:
cat
dog
boy
girl
mouse
house
test.file:
football
hockey
Replace_Flag
baseball
... (4 Replies)
Discussion started by: bblondin
4 Replies
10. Shell Programming and Scripting
Literally cannot get this one, guys. Single line replacement is simple, but I am not understanding the correct syntax for including a new line feed into the substitution part.
Here's what I got. (Cannot use perl)
#!/bin/sh
set -f
#Start Perms
export HOME=/home/test_user
# End Perms... (6 Replies)
Discussion started by: Parallax
6 Replies
OD(1) General Commands Manual OD(1)
NAME
od - octal, decimal, hex, ascii dump
SYNOPSIS
od [ -format ] [ file ] [ [+]offset[.][b] [label] ]
DESCRIPTION
Od displays file, or it's standard input, in one or more dump formats as selected by the first argument. If the first argument is missing,
-o is the default. Dumping continues until end-of-file.
The meanings of the format argument characters are:
a Interpret bytes as characters and display them with their ACSII names. If the p character is given also, then bytes with even parity
are underlined. The P character causes bytes with odd parity to be underlined. Otherwise the parity bit is ignored.
b Interpret bytes as unsigned octal.
c Interpret bytes as ASCII characters. Certain non-graphic characters appear as C escapes: null= , backspace=, formfeed=f, new-
line=
, return=
, tab= ; others appear as 3-digit octal numbers. Bytes with the parity bit set are displayed in octal.
d Interpret (short) words as unsigned decimal.
f Interpret long words as floating point.
h Interpret (short) words as unsigned hexadecimal.
i Interpret (short) words as signed decimal.
l Interpret long words as signed decimal.
o Interpret (short) words as unsigned octal.
s[n] Look for strings of ascii graphic characters, terminated with a null byte. N specifies the minimum length string to be recognized.
By default, the minimum length is 3 characters.
v Show all data. By default, display lines that are identical to the last line shown are not output, but are indicated with an ``*'' in
column 1.
w[n] Specifies the number of input bytes to be interpreted and displayed on each output line. If w is not specified, 16 bytes are read for
each display line. If n is not specified, it defaults to 32.
x Interpret (short) words as hexadecimal.
An upper case format character implies the long or double precision form of the object.
The offset argument specifies the byte offset into the file where dumping is to commence. By default this argument is interpreted in
octal. A different radix can be specified; If ``.'' is appended to the argument, then offset is interpreted in decimal. If offset begins
with ``x'' or ``0x'', it is interpreted in hexadecimal. If ``b'' (``B'') is appended, the offset is interpreted as a block count, where a
block is 512 (1024) bytes. If the file argument is omitted, an offset argument must be preceded by ``+''.
The radix of the displayed address will be the same as the radix of the offset, if specified; otherwise it will be octal.
Label will be interpreted as a pseudo-address for the first byte displayed. It will be shown in ``()'' following the file offset. It is
intended to be used with core images to indicate the real memory address. The syntax for label is identical to that for offset.
SEE ALSO
adb(1)
BUGS
A file name argument can't start with ``+''. A hexadecimal offset can't be a block count. Only one file name argument can be given.
It is an historical botch to require specification of object, radix, and sign representation in a single character argument.
4th Berkeley Distribution April 29, 1985 OD(1)