06-27-2011
Grep search and append
I'm sure glad I found this forum... This is my first post, so please be gentle...
I tried searching everywhere, but the terminology is so common that I cannot find a solution to my problem.
I'm looking for a GREP statement to do the following...
I need a search and append function that will search for the word "The " at the beginning of a line, and if it exists, trim it, and append it to the end of the line.
(note: it needs to ensure the first 4 chars are "the " and not modify fields with "the" in the middle of the text.
Two examples:
BEFORE:
The Beatles
The Beginning and the End
AFTER:
Beatles, The
Beginning and the End, The
Can anyone point me to a good example, or help me out? It would be much appreciated!
Thanks in advance!
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
All,
I stuck up for the logic, how to implement the below thing in script.
-Search for <a class="string-array"> line and in next line of search string append with <string>java</string> in a xml file
The problem here is, <a class="string-array"> occurs multiple places in the xml. I just... (13 Replies)
Discussion started by: vino_hymi
13 Replies
2. Shell Programming and Scripting
Dear All,
I want search two lines and append some string in between these lines.
Input file
tmp,123
,10:123
tmp,666
,50:999
tmp,2:19800
5,3:21.
tmp,2:19800
55555555
tmp,2:19800
5,3:21.Output should be
tmp,123
,10:123
tmp,666
,50:999
tmp,2:19800 (4 Replies)
Discussion started by: arvindng
4 Replies
3. Shell Programming and Scripting
Hi
I am trying to search for a particular occurrence of a string in a file, and if found, append another string to the end of that line.
Here is my file contents:
column1 userlist default nowrite=3 output=4
column2 access default nowrite=3
Here is the code:
A="user=1... (1 Reply)
Discussion started by: bludhemn
1 Replies
4. Shell Programming and Scripting
Hi ,
I have a file myhost.txt which contains below,
127.0.0.1 localhost
1.17.1.5 atrpx958
11.17.10.11 atrpx958zone nsybhost
I need to append words only after "atrpx958" like 'myhost' and 'libhost' and not after atrpx958zone.
How to search the word atrpx958 only in... (2 Replies)
Discussion started by: gsreeni
2 Replies
5. Shell Programming and Scripting
Hi,
I am new to Unix. Please help me in finding solution for the below scenario.
I have a flat file that contains data like
378633410|3013505414|new_378633410|ALBERT|WALLS|378633410|Rew|||||||
351049045|239|new_351049045|JIM|COOK|351049045|Rew|||||||... (6 Replies)
Discussion started by: anandek
6 Replies
6. Shell Programming and Scripting
I have file .
cat hello.txt
Hello World
I would like to append a string "Today " so the output is
cat hello.txt
Hello World Today
I dont know which line number does the "Hello World" appears otherwise I could have used the Line number to search and append . (3 Replies)
Discussion started by: gubbu
3 Replies
7. Shell Programming and Scripting
Hello,
I want to search a string/substring from the second column in file in another file and append the first found record in second file to the end of the record in the first file. Both files are tab delimited.
All lines with KOG in col13 do not need to be searched as it will not be... (7 Replies)
Discussion started by: gina.lizar
7 Replies
8. Shell Programming and Scripting
Have a string as below in a file.
"anohter boy has id 000921 and girl has id=655 of roll number"
using grep below commands with grep commands but able to get one string at a time, not able to append.
less <filename> | grep -o -P '(?<=id ).*(?=and )'
less <filename> | grep -o -P... (1 Reply)
Discussion started by: Satyak
1 Replies
9. Shell Programming and Scripting
Hello all,
I have a verilog file as following (part of it):
old.v:
bw_r_rf16x32 AUTO_TEMPLATE (
1957 // .rst_tri_en (mem_write_disable),
1958 .rclk (clk),
1959 .bit_wen (dva_bit_wr_en_e),
1960 .din ... (5 Replies)
Discussion started by: Zam_1234
5 Replies
10. UNIX for Beginners Questions & Answers
Lets say I have a massive directory which is filled with other directories all filled with different c++ scripts and I want a listing of all the scripts that contain the string: "this string". Is there a way to use a grep search for that? I tried:
grep -lr "this string" *
but I do not... (3 Replies)
Discussion started by: Circuits
3 Replies