Sponsored Content
Top Forums Shell Programming and Scripting How to Toggle Flag/Switch Value with Sed Post 302493501 by fiendracer on Thursday 3rd of February 2011 12:47:29 AM
Old 02-03-2011
There's probably a few ways to do this and I'm pretty sure this is not the easiest-
Code:
/^flag/ {
  /1$/ {
    s/flag=1/flag=0/
    b
  }
  /0$/ {
    s/flag=0/flag=1/
  }
}

But run w/ this-
Code:
> sed -f flg-script

You can put in flag=0, hit enter and it will return flag=1. And vice-versa
Or run flag=0 in flag.txt as such-
Code:
> sed -f flg-script < flag.txt

Good luck.

---------- Post updated at 12:47 AM ---------- Previous update was at 12:33 AM ----------

Oh just wait!
Here's a one liner and neat and clean-
Code:
/flag/ y/01/10/

w00t.

Last edited by Franklin52; 02-03-2011 at 03:35 AM.. Reason: Please use code tags, thank you
This User Gave Thanks to fiendracer For This Post:
 

9 More Discussions You Might Find Interesting

1. Programming

How to toggle BACKSPACE/DEL function for backArrow key for terminal other than xterm?

Hi all, I've got the problem which I can't resolve with my knowledge :) For xterm terminal we have resource class XTerm*backarrowKey. If we set it to true, backspace code (ASCII 0x8) will be sent to program. We can get it using e.g. getc() function. If it is disabled getc() returns DEL(0x7F). ... (0 Replies)
Discussion started by: dmitryb
0 Replies

2. Shell Programming and Scripting

Toggle Hidden Files Mac OS X

Hi all, I have been using Ubuntu for 2 years now, and a few days ago I bought a Macbook. This is my first time using a Mac, so I have spent the better of two days learning the user interface, and configuring my Macbook. One thing I noticed is that there is no easy way to turn on and off hidden... (0 Replies)
Discussion started by: Omniwheel
0 Replies

3. Shell Programming and Scripting

Perl script to toggle through dates by week

Hi, I need help to toggle through dates on a weekly basis to be fed into a script as inputs. The format should be: yyyy/mm/dd (start) yyyy/mm/dd (end), where end date is 7 days increments. The date (start) would be input as an ARGV and would continue until current date. I can check... (2 Replies)
Discussion started by: subhap
2 Replies

4. Shell Programming and Scripting

pass variable to sed like in awk (-v switch)

hi all is possible to pass shell (bash) variable to sed like it is in awk? example: awk script is storred in awk.awk file and I am passing variable called var to this file. $ cat awk.awk {if ($5==var) print $0} so it works when i issue $ bash_var=24 $ ls -l | awk -v... (1 Reply)
Discussion started by: wakatana
1 Replies

5. Programming

toggle bit

how can I toggle all the bits of any given number using a shortest C code (5 Replies)
Discussion started by: rupeshkp728
5 Replies

6. Shell Programming and Scripting

what is the switch to let sed edit and save file

I remember there is a sed switch i can use to edit and save the file at the same time, but i cannot recall it at all. so instead of -> sed 's/A/B/' file > file-tmp -> mv file-tmp file what can i do to just let sed edit and save the "file" (4 Replies)
Discussion started by: fedora
4 Replies

7. UNIX for Dummies Questions & Answers

sed "-n" switch

Hi Guys, i'm exploring sed and failed to understand the following. Can anyone with more knowledge of this explain this better. I have to read lines 4 to 6 in a file so i used the following command : sed '4,6 p' file but the above prints all lines instead! . when i use the -n... (3 Replies)
Discussion started by: Irishboy24
3 Replies

8. UNIX for Dummies Questions & Answers

[Solved]Can anyone tell me why -H flag with sudo doesn't switch to the target user's home directory?

I have checked the man page ,which says : The -H (HOME) option sets the HOME environment variable to the homedir of the target user (root by default) as specified in passwd(5). By default, sudo does not modify HOME But I have tried below command: #... (1 Reply)
Discussion started by: Michaelw321
1 Replies

9. Shell Programming and Scripting

sed print flag

I have an input file that looks something like this: .... key1: ABC .... key2: DEF .... key1: GGG .... key2: HHH .... The row of dots represents any number of lines that don't contain the strings "key1:" or "key2:" The strings key1: and key2: will always appear alternately as in the... (8 Replies)
Discussion started by: pmennen
8 Replies
Gtk2::CellRendererToggle(3)				User Contributed Perl Documentation			       Gtk2::CellRendererToggle(3)

NAME
Gtk2::CellRendererToggle HIERARCHY
Glib::Object +----Glib::InitiallyUnowned +----Gtk2::Object +----Gtk2::CellRenderer +----Gtk2::CellRendererToggle METHODS
cellrenderer = Gtk2::CellRendererToggle->new boolean = $toggle->get_active $toggle->set_active ($setting) o $setting (boolean) boolean = $toggle->get_radio $toggle->set_radio ($radio) o $radio (boolean) PROPERTIES
'activatable' (boolean : readable / writable / private) The toggle button can be activated 'active' (boolean : readable / writable / private) The toggle state of the button 'inconsistent' (boolean : readable / writable / private) The inconsistent state of the button 'indicator-size' (integer : readable / writable / private) Size of check or radio indicator 'radio' (boolean : readable / writable / private) Draw the toggle button as a radio button SIGNALS
toggled (Gtk2::CellRendererToggle, string) SEE ALSO
Gtk2, Glib::Object, Glib::InitiallyUnowned, Gtk2::Object, Gtk2::CellRenderer COPYRIGHT
Copyright (C) 2003-2008 by the gtk2-perl team. This software is licensed under the LGPL. See Gtk2 for a full notice. perl v5.12.1 2010-07-05 Gtk2::CellRendererToggle(3)
All times are GMT -4. The time now is 10:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy