09-04-2013
What exactly do you mean by search for the first line and do a conditional on two lines after and then replace the middle line if the condition is met as your post is confusing so state your problem clearly if you want someone to help you out because we cant read your mind...
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi All,
I have a file that I need to be able to find a pattern match on a line, search that line for a text pattern, and replace that text.
An example of 4 lines in my file is:
1. MatchText_randomNumberOfText moreData ReplaceMe moreData
2. MatchText_randomNumberOfText moreData moreData... (4 Replies)
Discussion started by: Crypto
4 Replies
2. Shell Programming and Scripting
Hello,
I would like to delete all the footnotes in all my htm files. Hence, I have to delete the whole font tag pairs, i.e. deleting everything between the begin/end font tags.
I create a testfile, of which data parts of all four lines are the same except for the number of font tag pairs,... (3 Replies)
Discussion started by: cibalo
3 Replies
3. Shell Programming and Scripting
Dear All,
i want to search particular string and want to replance next line value.
following is the test file.
search string is
tmp,???
,10:1 "???" may contain any 3 character it should remain the same and next line replace with ,10:50
tmp,123 --- if match tmp,??? then... (3 Replies)
Discussion started by: arvindng
3 Replies
4. Shell Programming and Scripting
Hi
I am trying to search and replace a multi line pattern in a php file using awk.
The pattern starts with
<div id="navbar">
and ends with
</div>
and spans over an unknown number of lines.
I need the command to be a one liner.
I use the "record separator" like this :
awk -v... (8 Replies)
Discussion started by: louisJ
8 Replies
5. Shell Programming and Scripting
Hi all.
I have the following command that is successfully searching for any one of the strings on all lines of a file and replacing it with the instructed value.
cat inputFile | awk '{gsub(/aaa|bbb|ccc|ddd/,"1234")}1' > outputFile
This does in fact replace any occurrence of aaa, bbb,... (2 Replies)
Discussion started by: dazhoop
2 Replies
6. Shell Programming and Scripting
Need to remove rest of line after the equals sign on search pattern from the searchfile. Can anybody help. Couldn't find any similar example in the forum:
infile:
64_1535: Delm. = 86 var, aaga
64_1535: Fran. = 57 ex. ccc
64_1639: Feb. = 26 (link). def
64_1817: mar. = 3/4. drz ... (7 Replies)
Discussion started by: sdf
7 Replies
7. Shell Programming and Scripting
I have a list of files all over a file system e.g.
/home/1/foo/bar.x
/www/sites/moose/foo.txtI'm looking for strings in these files and want to replace each occurrence with a replacement string, e.g.
if I find: '#@!^\&@ in any of the files I want to replace it with: 655#@11, etc.
There... (2 Replies)
Discussion started by: spacegoose
2 Replies
8. Shell Programming and Scripting
I need to be able to search for a string in the first column and if that string exists than replace the nth column with "-9.99".
AW12000012012 2.38 1.51 3.01 1.66 0.90 0.91 1.22 0.82 0.57 1.67 2.31 3.63 0.00
AW12000012013 1.52 0.90 1.20 1.34 1.21 0.67 ... (14 Replies)
Discussion started by: ncwxpanther
14 Replies
9. Shell Programming and Scripting
All, I appreciate any help you can offer here as this is well beyond my grasp of awk/sed...
I have an input file similar to:
&LOG
&LOG Part: "@DB/TC10000021855/--F"
&LOG
&LOG
&LOG Part: "@DB/TC10000021852/--F"
&LOG Cloning_Action: RETAIN
&LOG Part: "@DB/TCCP000010713/--A"
&LOG
&LOG... (5 Replies)
Discussion started by: KarmaPoliceT2
5 Replies
10. UNIX for Dummies Questions & Answers
Hi Folks,
I have the file in which I need to multiply the content of a line and replace the initial content of that line with the obtained answer.
For example if this is my input file file1.txt
2.259314750 xxxxxx
1.962774350 xxxxxx
2.916817290 xxxxxx
1.355026900 ... (4 Replies)
Discussion started by: Madiouma Ndiaye
4 Replies
LEARN ABOUT NETBSD
qsubst
QSUBST(1) BSD General Commands Manual QSUBST(1)
NAME
qsubst -- query-replace strings in files
SYNOPSIS
qsubst str1 str2 [flags] file [file [...]]
DESCRIPTION
qsubst reads its options (see below) to get a list of files. For each file on this list, it then replaces str1 with str2 wherever possible
in that file, depending on user input (see below). The result is written back onto the original file.
For each potential substitution found, the user is prompted with a few lines before and after the line containing the string to be substi-
tuted. The string itself is displayed using the terminal's standout mode, if any. Then one character is read from the terminal. This is
then interpreted as follows (this is designed to be like Emacs' query-replace-string):
space Replace this occurrence and go on to the next one.
. Replace this occurrence and don't change any more in this file (i.e., go on to the next file).
, Tentatively replace this occurrence. The lines as they would look if the substitution were made are printed out. Then another
character is read and it is used to decide the result as if the tentative replacement had not happened.
n Don't change this one; just go on to the next one.
^G Don't change this one or any others in this file, but instead simply go on to the next file.
! Change the rest in this file without asking, then go on to the next file (at which point qsubst will start asking again).
? Print out the current filename and ask again.
The first two arguments to qsubst are always the string to replace and the string to replace it with. The options are as follows:
-w The search string is considered as a C symbol; it must be bounded by non-symbol characters. This option toggles. ('w'
for 'word'.)
-!
-go
-noask Enter ! mode automatically at the beginning of each file.
-nogo
-ask Negate -go, that is, ask as usual.
-cN (Where N is a number.) Give N lines of context above and below the line with the match when prompting the user.
-CAN (Where N is a number.) Give N lines of context above the line with the match when prompting the user.
-CBN (Where N is a number.) Give N lines of context below the line with the match when prompting the user.
-f filename The filename argument is one of the files qsubst should perform substitutions in.
-F filename qsubst reads filename to get the names of files to perform substitutions in. The names should appear one to a line.
The default amount of context is -c2, that is, two lines above and two lines below the line with the match.
Arguments not beginning with a - sign in the options field are implicitly preceded by -f. Thus, -f is really needed only when the file name
begins with a - sign.
qsubst reads its options in order and processes files as it gets them. This means, for example, that a -go will affect only files named
after the -go.
The most context you can get is ten lines each, above and below.
str1 is limited to 512 characters; there is no limit on the size of str2. Neither one may contain a NUL.
NULs in the file may cause qsubst to make various mistakes.
If any other program modifies the file while qsubst is running, all bets are off.
AUTHORS
der Mouse <mouse@rodents.montreal.qc.ca>
BSD
September 4, 1999 BSD