Sponsored Content
Full Discussion: Tough Substituion command
Top Forums UNIX for Advanced & Expert Users Tough Substituion command Post 302233479 by BMDan on Sunday 7th of September 2008 09:54:18 PM
Old 09-07-2008
Quote:
Originally Posted by ggggdddd
I have lines like:

Mg2.qns W=0.175u
Mg2.qpsb W=0.175u
Mg4.qns W=0.175u
Mg4.qpsb W=0.175u

Which I need to become:
Mg2.qns W=wmg2qns
Mg2.qpsb W=wmg2qpsb
Mg4.qns W=wmg4qns
Mg4.qpsb W=wmg4qpsb

To acheive this individually line by line I use a command like:
:g/Mg2\.qns/s/W=.*/W=wmg2qns/

However I wish to acheive this for all lines in one command

I can find all the lines containing the concerned words by using:

:g/Mg[24]\.q[np]s/s/??????????????????????

I do not know how to fill up the second part of the command represented by question marks. Any idea?
Not clear why there's a colon at the start; is this vim? Here's how to do it in vim:
Code:
:%s/Mg\([24]\).\(q[np]s[b]?\) W=0\.175u/Mg\1.\2 W=wmg\1\2/g

 

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Env Variable substituion in Sed (-s option)

Folks, I've been trying to use the ENV variable with slashes(/) in its value inside the sed substitution.. Sed 's/myval/'$MYVAL'/' file1 >> file.tmp If MYVAL=<sometext>, it works. if MYVAL=/home/venkat, it doesnt. *************************** bash-2.05$ export VAL=/home/venkat... (5 Replies)
Discussion started by: gvsreddy_539
5 Replies

2. Shell Programming and Scripting

Perl Arrays and Substituion

@xray =~ s/^ *//g; @xray =~ s/ *$//g; @xray =~ s/\s+/ /g; Guess I have a two part question ... First Is there a way to make substitutions, remove leading spaces, trailing spaces, and crunch multiple spaces into a single space, to the entire array, or must the substitutions be done on on... (1 Reply)
Discussion started by: popeye
1 Replies

3. Solaris

bad substituion error

Dear All i am getting "bad substituion" error in the follwing piece of code when i run from crontab.however it works if i run directly from my machine. #!/bin/bash for i in `cat abc` do part1=${i:0:12} ; part2=${i:13:27} ; echo "$part1,$part2">> def done (1 Reply)
Discussion started by: asadlone
1 Replies

4. UNIX for Dummies Questions & Answers

tough parsing

I have a string as "Period= 20090531 Client Name= Clayton Lumbar Company Destination= MD" I want to parse the string and store it in 3 different variables. $period (should get value 20090531) $client (should get value "Clayton Lumbar company") $dest (should get value MD) How can I do... (3 Replies)
Discussion started by: paruthiveeran
3 Replies

5. UNIX for Advanced & Expert Users

Tough Oracle Logic in Ux

How Can this logic be implemented in Unix SELECT B.SERVICE_TYPE || '|' || B.TOTAL_TYPE || '|' || B.CALL_INDICATOR || '|' || B.A_NUMBER || '|' || B.APN || '|' || B.DAY || '|' || B.HOUR ||... (3 Replies)
Discussion started by: magedfawzy
3 Replies

6. Shell Programming and Scripting

A very tough exercise

hello everyone!:) I have an exercise which I think is difficult for beginner like me. Here is the exercise Create a shell script, which takes a directory as command line argument. Script displays ten first lines from every text file in that directory. After displaying the lines from the... (1 Reply)
Discussion started by: googlevn
1 Replies

7. Shell Programming and Scripting

Variable in awk substituion

I have a file with 20 blank spaces. I want to substitute each blank space for a string, and part of that string should include an incremental number Code while read line3 do awk -v var=${line3} '{i=var; sub("^]*$", "\\&\n@target G0.S"'$i'"\n@type xy"); print $0}'... (1 Reply)
Discussion started by: chrisjorg
1 Replies

8. UNIX for Beginners Questions & Answers

Bad substituion error : Dont understand why

Hi Folks - I'm getting the following error message when executing my script: $ chmod +x Winexe_Admin.sh $ ./Winexe_Admin.sh Script Name: Winexe_Admin.sh Script Name without EXT: Winexe_Admin ./Winexe_Admin.sh: line 43: ${_MAINPATH}${_LOGPATH}${LOGPATH$}${_YEAR}_${_MONTH}${_DAY}: bad... (2 Replies)
Discussion started by: SIMMS7400
2 Replies
VIMDIFF(1)						      General Commands Manual							VIMDIFF(1)

NAME
vimdiff - edit two, three or four versions of a file with Vim and show differences SYNOPSIS
vimdiff [options] file1 file2 [file3 [file4]] gvimdiff DESCRIPTION
Vimdiff starts Vim on two (or three or four) files. Each file gets its own window. The differences between the files are highlighted. This is a nice way to inspect changes and to move changes from one version to another version of the same file. See vim(1) for details about Vim itself. When started as gvimdiff the GUI will be started, if available. In each window the 'diff' option will be set, which causes the differences to be highlighted. The 'wrap' and 'scrollbind' options are set to make the text look good. The 'foldmethod' option is set to "diff", which puts ranges of lines without changes in a fold. 'foldcolumn' is set to two to make it easy to spot the folds and open or close them. OPTIONS
Vertical splits are used to align the lines, as if the "-O" argument was used. To use horizontal splits instead, use the "-o" argument. For all other arguments see vim(1). SEE ALSO
vim(1) AUTHOR
Most of Vim was made by Bram Moolenaar, with a lot of help from others. See ":help credits" in Vim. 2001 March 30 VIMDIFF(1)
All times are GMT -4. The time now is 10:28 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy