05-02-2006
Search and replace to first occurrence of string
Hi all,
I have a very large; delimited file. In vi I would like to replace:
CSACT_DY;AVG_UEACT1;uesPerActiveLinkSetSize_1;#;A
CSACT_DY;AVG_UEACT2;uesPerActiveLinkSetSize_2;#;A
CSACT_DY;AVG_UEACT3;uesPerActiveLinkSetSize_3;#;A
with:
CSACT_DY;AVG_UEACT1;Average uesPerActiveLinkSetSize_1;#;A
CSACT_DY;AVG_UEACT2;Average uesPerActiveLinkSetSize_2;#;A
CSACT_DY;AVG_UEACT3;Average uesPerActiveLinkSetSize_3;#;A
The only common thing is the AVG_. The last part is various lengths and ends in a mixture of numbers and capital letters
I tried
:%s/AVG_\(.*\);/AVG_\1;Average
but this matches to the last ;
Is there any way to change the default in vi to match to the first ;?
I have managed to hack around it by:
cat file.txt| awk -F\; '{print $1 ";" $2 "####" $3 ";" $4 ";" $5}' > file_2.txt
vi file_2.txt
:%s/AVG_\(.*\)####/AVG_\1;Average /
:%s/####/;
All weird and wonderful solutions welcome. Knowing vi, there must be about a hundred ways of doing this.
Cheers!
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
hi all,
I have a text file with following content
PAGENUMBER
asasasa
asasasa
PAGENUMBER
sasasasasa
PAGENUMBER
using sed i want to replace PAGENUMBER by occurrence count
eg
1
asasasa
asasasa
2
sasasasasa
3 (4 Replies)
Discussion started by: uttamhoode
4 Replies
3. UNIX for Dummies Questions & Answers
Hi All,
My requisite is to search for the string "0108"(which is the year and has come in the wrong year format) in a particular column say 4th column in a tab delimited file and then replace it with 2008(the correct year format) in the same position where 0108 was found in the same file..The... (27 Replies)
Discussion started by: ganesh_248
27 Replies
4. Shell Programming and Scripting
Hello: I have another question. Please consider the following two sample, tab-delimited files:
File_1:
Abf1 YKL112w
Abf1 YAL054c
Abf1 YGL234w
Ace2 YKL150w
Ace2 YNL328c
Cup9 YDR441c
Cup9 YDR442w
Cup9 YEL040w
...
File 2:
...
ABF1 YKL112W
ACE2 YLR131C (9 Replies)
Discussion started by: gstuart
9 Replies
5. Shell Programming and Scripting
Hello,
I really would appreciate some help with a bash script for some string manipulation on an SQL dump:
I'd like to be able to rename "sites/WHATEVER/files" to "sites/SOMETHINGELSE/files" within the sql dump.
This is quite easy with sed:
sed -e... (1 Reply)
Discussion started by: otrotipo
1 Replies
6. Shell Programming and Scripting
Ok,
So I have a huge file that has over 12000 lines in it.
in this file, there are 589 occurrences of the string "use five-minute-interval" spread in various areas in the file.
How can i replace the the last 250 of the occurrences of "use five-minute-interval" with "use... (10 Replies)
Discussion started by: SkySmart
10 Replies
7. 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
8. AIX
Hi All,
I have a requirement to replace consecutive occurence of same string nedd to be replaced. Below is the input and desired output.
Input:
---------
123.5|ABC|.|.|.
234.4|DEF|.|.|.|.|.|
Output:
---------
123.5|ABC|||.
234.4|DEF|||||
so basically "|.|" need to be replaced with... (9 Replies)
Discussion started by: ureddy
9 Replies
9. Shell Programming and Scripting
####Solved####
Hello,
My aim is to replace searched string with incremented value under ubuntu 16.04.
Example:
aasasasas 9030 31wwo weopwoep
weerasas 9030 ew31wo ieopwoep
bbqqqsas 9030 ew3swo ieeopwoep
ccsaqpas 9030 ewiro o2opwoep
Expected:
aasasasas 9030 31wwo weopwoep
weerasas 9031... (2 Replies)
Discussion started by: baris35
2 Replies
10. UNIX for Beginners Questions & Answers
I have the below string which i need to compare with a file and replace this string in the file which matches closely. Can anyone help me on this.
string(Scenario 1)- user::r--,user::ourfrd:r--
String(Scenario 2)- user::r--
File
****
# file: /local/Desktop/myfile
# owner: me
# group:... (6 Replies)
Discussion started by: sarathy_a35
6 Replies
LEARN ABOUT DEBIAN
g_bond
g_bond(1) GROMACS suite, VERSION 4.5.4-dev-20110404-bc5695c g_bond(1)
NAME
g_bond - calculates distances between atoms
VERSION 4.5.4-dev-20110404-bc5695c
SYNOPSIS
g_bond -f traj.xtc -n index.ndx -s topol.tpr -o bonds.xvg -l bonds.log -d distance.xvg -[no]h -[no]version -nice int -b time -e time -dt
time -[no]w -xvg enum -blen real -tol real -[no]aver -[no]averdist
DESCRIPTION
g_bond makes a distribution of bond lengths. If all is well a Gaussian distribution should be made when using a harmonic potential. Bonds
are read from a single group in the index file in order i1-j1 i2-j2 through in-jn.
-tol gives the half-width of the distribution as a fraction of the bondlength ( -blen). That means, for a bond of 0.2 a tol of 0.1 gives a
distribution from 0.18 to 0.22.
Option -d plots all the distances as a function of time. This requires a structure file for the atom and residue names in the output. If
however the option -averdist is given (as well or separately) the average bond length is plotted instead.
FILES
-f traj.xtc Input
Trajectory: xtc trr trj gro g96 pdb cpt
-n index.ndx Input
Index file
-s topol.tpr Input, Opt.
Structure+mass(db): tpr tpb tpa gro g96 pdb
-o bonds.xvg Output
xvgr/xmgr file
-l bonds.log Output, Opt.
Log file
-d distance.xvg Output, Opt.
xvgr/xmgr file
OTHER OPTIONS
-[no]hno
Print help info and quit
-[no]versionno
Print version info and quit
-nice int 19
Set the nicelevel
-b time 0
First frame (ps) to read from trajectory
-e time 0
Last frame (ps) to read from trajectory
-dt time 0
Only use frame when t MOD dt = first time (ps)
-[no]wno
View output .xvg, .xpm, .eps and .pdb files
-xvg enum xmgrace
xvg plot formatting: xmgrace, xmgr or none
-blen real -1
Bond length. By default length of first bond
-tol real 0.1
Half width of distribution as fraction of blen
-[no]averyes
Average bond length distributions
-[no]averdistyes
Average distances (turns on -d)
KNOWN PROBLEMS
- It should be possible to get bond information from the topology.
SEE ALSO
gromacs(7)
More information about GROMACS is available at <http://www.gromacs.org/>.
Mon 4 Apr 2011 g_bond(1)