Replace all but skip first instance in a line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace all but skip first instance in a line
# 8  
Old 06-21-2011
A sed alternative:
Code:
sed 's/~/\
/; s/~//g; s/\n/~/'

Since we are guaranteed that initially there will not be any newlines in sed's pattern space, we can substitute the first occurrence of ~ with a newline. Then we can delete any remaining ~ before restoring the newline back to a ~.

Regards,
Alister
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Skip to next line if the variable is string

Hi I have the follwoing requirement I have a file as follows: # cat priy yyy.poweroff_cmd = /sbin/poweroff hhh.powersave-nap = 1 When this file is provided as input, I first used "awk" command and saved variables present after "=" replace=$line replace1=`echo $line | awk -F "="... (3 Replies)
Discussion started by: Priya Amaresh
3 Replies

2. Shell Programming and Scripting

Replace every second instance of delimeter

Hi, Need help on replacing every second instance of delimeter. Scenario: var="Name1,Value1,Name2,Value2,Name3,Value3,Name4,Value" I want every second "," to replace with "|" I tried like below echo $var| sed 's/,/|/2' But, it's not working. Expected output: ... (4 Replies)
Discussion started by: Sumanthsv
4 Replies

3. Shell Programming and Scripting

Skip first and last line

Hi All I have a sample file like below: 012312112 1372422843 1236712 1372422843 1275127 3109301010 from which I wan't to: 1.)delete... (10 Replies)
Discussion started by: swasid
10 Replies

4. Shell Programming and Scripting

sed command to skip the first line during find and replace operation

Hi Gurus, I did an exhaustive search for finding the script using "sed" to exclude the first line of file during find and replace. The first line in my file is the header names. Thanks for your help.. (4 Replies)
Discussion started by: ks_reddy
4 Replies

5. Shell Programming and Scripting

Script to replace last instance of . between two consecutive = sign by ,

Suppose you have a line like this: cn=user.blr.ou=blr.india.o=company The line should be converted like this: cn=user.blr,ou=blr.india,o=comapny Was wondering how to do that using shell script. Please use tags where appropriate, thank you (4 Replies)
Discussion started by: saurabhkoar
4 Replies

6. Shell Programming and Scripting

replace but skip data between certain commas

OK, I am one needy dude. However, how can I make the program NOT change any of the values BETWEEN the first and second "," ? I dont want any of the numbers changed that are preceded by "AT". I want ALL other numeric values > 300 changed to 300. cat qin.csv |head... (4 Replies)
Discussion started by: herot
4 Replies

7. Shell Programming and Scripting

replace nth instance of string

Hi all, I have file with following content ........................... ..........TEST.......... ..........TEST.......... ..................... .....TEST.......... ..................... ..................... .....TEST.......... I want to replace nth "TEST" with "OK" using... (4 Replies)
Discussion started by: uttamhoode
4 Replies

8. Shell Programming and Scripting

sed replace 2nd instance

Hello, I want to replace 2nd instance of "foo" in a file use sed. Any suggestions? (2 Replies)
Discussion started by: katrvu
2 Replies

9. Shell Programming and Scripting

replace first instance(not first instance in line)

Alright, I think I know what I am doing with sed(which probably means I don't). But I cant figure out how to replace just the first occurance of a string. I have tried sed, ed, and grep but can't seem to figure it out. If you have any suggestions I am open to anything! (3 Replies)
Discussion started by: IronHorse7
3 Replies

10. Shell Programming and Scripting

Skip new line

Hi, how can I skip the new line of echo? In SH!!!! echo "the date is :" date and result I want is the date is : Tue Oct 11 22:24:37 WEST 2005 I've already tried including the \c inside the echo, but it didn't work. Thanks! (2 Replies)
Discussion started by: pmpx
2 Replies
Login or Register to Ask a Question
ZORPCTL(8)							  [FIXME: manual]							ZORPCTL(8)

NAME
zorpctl_ - Start and stop zorp instances. SYNOPSIS
zorpctl command [options [instances/@instance-list-file]] DESCRIPTION
zorpctl starts and stops zorp(8) instances based on the contents of the instances.conf(5) file. Multiple instance names can be specified in the command-line or in a file to start or stop several instances. If an error occurs while stopping or starting an instance, an exclamation mark is appended to the instance name as zorpctl processes the request, and a summary is printed when the program exits. If no instance is specified, the command is executed on all instances. The instances to be controlled can be specified in a file instead of listing them in the command line, e.g.: zorpctl command options instances.txt. The instances.txt should contain every instance name in a new line. COMMANDS
start Starts the specified Zorp instance(s). force-start Starts the specified Zorp instance(s) even if they are disabled. stop Stops the specified Zorp instance(s). force-stop Forces the specified Zorp instance(s) to stop using the KILL signal. restart Restart the specified Zorp instance(s). force-restart Forces the specified Zorp instance(s) to restart by stopping them using the KILL signal. reload Reload the specified Zorp instance(s). status Display the status of the specified Zorp instance(s). --verbose or -v Display detailed status information. gui-status Display the status of the specified Zorp instance(s) in an internal format easily parsable by ZMC. NOTE: This command is mainly used internally within Zorp, and the structure of its output may change. version Display version information on Zorp. inclog Raise the verbosity (log) level of the specified Zorp instance(s) by one. declog Decrease the verbosity (log) level of the specified Zorp instance(s) by one. log Change various log related settings in the specified Zorp instance(s) using the following options: --vinc or -i Increase verbosity level by one. --vdec or -d Decrease verbosity level by one. --vset <verbosity> or -s <verbosity> Set verbosity level to <verbosity>. --log-spec <spec> or -S <spec> Set verbosity mask on a per category basis. The format of this value is described in zorp(8). --help or -h Display this help screen on the options of the log command. szig Display internal information from the specified Zorp instance(s). The information to be disblayed can be specified with the following options: --walk or -w Walk the specified tree. --root [node] or -r [node] Set the root node of the walk operation to [node]. --help or -h Display a brief help on the options of the szig command. help Display a brief help message. EXAMPLES
zorpctl start zorp_ftp The command above starts the zorp instance named zorp-ftp with parameters described in the instances.conf file. FILES
The default location for instances.conf is /etc/zorp/instances.conf. AUTHOR
This manual page was written by the BalaBit Documentation Team <documentation@balabit.com>. COPYRIGHT
Copyright (C) 2006 BalaBit IT Security Ltd. All rights reserved. For more information about the legal status of this document please read: http://www.balabit.com/products/zorp/docs/legal_notice.bbq [FIXME: source] 03/06/2012 ZORPCTL(8)