Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Search and replace to first occurrence of string Post 302072393 by gilmord on Tuesday 2nd of May 2006 11:01:51 AM
Old 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

Perl: Search for string on line then search and replace text

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

SED replace string by occurrence

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

Search for a string and replace the searched string in the same position in samefile

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

Search, replace string in file1 with string from (lookup table) file2?

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

awk - replace number of string length from search and replace for a serialized array

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

Replace x Number of String Occurrence with Sed

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

Search for a string,delete the line and replace with new string in a file

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

Replace consecutive occurrence of string in same line

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

Replace first occurrence of a string in while loop

####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

Search partial string in a file and replace the string - UNIX

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
curl_global_init_mem(3) 					  libcurl Manual					   curl_global_init_mem(3)

NAME
curl_global_init_mem - Global libcurl initialisation with memory callbacks SYNOPSIS
#include <curl/curl.h> CURLcode curl_global_init_mem(long flags, curl_malloc_callback m, curl_free_callback f, curl_realloc_callback r, curl_strdup_callback s, curl_calloc_callback c ); DESCRIPTION
This function works exactly as curl_global_init(3) with one addition: it allows the application to set callbacks to replace the otherwise used internal memory functions. This man page only adds documentation for the callbacks, see the curl_global_init(3) man page for all the rest. When you use this function, all callback arguments must be set to valid function pointers. The prototypes for the given callbacks should match these: void *malloc_callback(size_t size); To replace malloc() void free_callback(void *ptr); To replace free() void *realloc_callback(void *ptr, size_t size); To replace realloc() char *strdup_callback(const char *str); To replace strdup() void *calloc_callback(size_t nmemb, size_t size); To replace calloc() CAUTION
Manipulating these gives considerable powers to the application to severely screw things up for libcurl. Take care! SEE ALSO
curl_global_init(3), curl_global_cleanup(3), libcurl 7.12.0 10 May 2004 curl_global_init_mem(3)
All times are GMT -4. The time now is 05:51 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy