08-06-2008
How do you know which ones to replace?
i.e. file1.txt contains name=Rajakumar, which you have used to replace the first occurrence of name=Kannan, however for Discipline you have replaced the last occurrence. There is no way you can programme this unless there are clear rules to follow.
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
Can someone tell me how I can do this?
e.g:
Say file1.txt contains:
today is monday
the 22 of
NOVEMBER
2010
and file2.txt contains:
the
11th
month
of
How do i replace the word NOVEMBER with (5 Replies)
Discussion started by: tuathan
5 Replies
3. Shell Programming and Scripting
Hi Experts,
I had to edit (a particular value) in header line of a very huge file so for that i wanted to search & replace a particular value on a file which was of 24 GB in Size. I managed to do it but it took long time to complete. Can anyone please tell me how can we do it in a optimised... (7 Replies)
Discussion started by: manishkomar007
7 Replies
4. Shell Programming and Scripting
Hello,
Some time ago a helpful awk file was provided on the forum which I give below:
NR==FNR{A=$0;next}{for(j in A){split(A,P,"=");for(i=1;i<=NF;i++){if($i==P){$i=P}}}}1
While it works beautifully on English and Latin characters i.e. within the ASCII range of 127, the moment a character beyond... (6 Replies)
Discussion started by: gimley
6 Replies
5. Shell Programming and Scripting
I am having a text file which is having more than 200 lines.
EX:
001010122 12000 BIB 12000 11200 1200003
001010122 2000 AND 12000 11200 1200003
001010122 12000 KVB 12000 11200 1200003
In the above file i want to search for string KVB and add/replace... (1 Reply)
Discussion started by: suryanarayana
1 Replies
6. Shell Programming and Scripting
Dear All
I am having a text file which is having more than 200 lines.
EX:
001010122 12000 BIB 12000 11200 1200003
001010122 2000 AND 12000 11200 1200003
001010122 12000 KVB 12000 11200 1200003
In the above file i want to search for string KVB... (5 Replies)
Discussion started by: suryanarayana
5 Replies
7. Shell Programming and Scripting
Hi,
I want to achieve something similar to what described in another post:
The difference is I want to add the line if the pattern is not found.
File 1:
A123, valueA, valueB
B234, valueA, valueB
C345, valueA, valueB
D456, valueA, valueB
E567, valueA, valueB
F678, valueA, valueB
... (11 Replies)
Discussion started by: jyu3
11 Replies
8. Shell Programming and Scripting
Hi,
Need your help for this scripting issue I have. I am not really good at this, so seeking your help.
I have a file looking similar to this:
Hello, i am human and name=ABCD.
How are you?
Hello, i am human and name=PQRS.
I am good.
Hello, i am human and name=ABCD.
Good bye.
Hello, i... (12 Replies)
Discussion started by: royzlife
12 Replies
9. Shell Programming and Scripting
Hi guys,
I have a text file named file1.txt that is formatted like this:
001 , ID , 20000
002 , Name , Brandon
003 , Phone_Number , 616-234-1999
004 , SSNumber , 234-23-234
005 , Model , Toyota
007 , Engine ,V8
008 , GPS , OFF
and I have file2.txt formatted like this:
... (2 Replies)
Discussion started by: An0mander
2 Replies
10. UNIX for Dummies Questions & Answers
Hi Everyone,
I have a requirement in ksh where i have a set of files in a directory. I need to search each and every file if a particular string is present in the file, delete that line and replace that line with another string expression in the same file.
I am very new to unix. Kindly help... (10 Replies)
Discussion started by: Pradhikshan
10 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