Sponsored Content
Full Discussion: Tricky sed required
Top Forums Shell Programming and Scripting Tricky sed required Post 302810555 by steadyonabix on Wednesday 22nd of May 2013 03:54:41 AM
Old 05-22-2013
Hi Bakunin,

That's certainly the kind of solution I am looking for. Unfortunately it doesn't quite do what I want, probably my fault for not taking a real file home with me.

I am back in work this morning and have just tried it against a real sample file -

Code:
"channel.facebook.com","['unknown', 'productivityloss']","[1001005, 1000041]","['standard', 'web2']"
"channel.facebook.com","['unknown', 'productivityloss']","[1001005, 1000041]","['standard', 'web2']"
"channel.facebook.com","['unknown', 'productivityloss']","[1001005, 1000041]","['standard', 'web2']"
"channel.facebook.com","['unknown', 'productivityloss']","[1001005, 1000041]","['standard', 'web2']"
"channel.facebook.com","['unknown', 'productivityloss']","[1001005, 1000041]","['standard', 'web2']"

Output of sed command -

Code:
"channel.facebook.com","'unknown', 'productivityloss'","1001005, 1000041","'standard', 'web2'"
"channel.facebook.com","'unknown', 'productivityloss'","1001005, 1000041","'standard', 'web2'"
"channel.facebook.com","'unknown', 'productivityloss'","1001005, 1000041","'standard', 'web2'"
"channel.facebook.com","'unknown', 'productivityloss'","1001005, 1000041","'standard', 'web2'"
"channel.facebook.com","'unknown', 'productivityloss'","1001005, 1000041","'standard', 'web2'"

So where I have single quoted strings inside brackets, I'm not losing the brackets.

This might be me, I had to change the outer quotes on your sed to " in order to get it to run -

Code:
sed ":start
      /\[[^]]*\'\]/ {
           s/\(\[[^]]*\)\'/\1/
           b start
      }
      s/\[\([^]]*\)\]/\1/g" $File

Would you be kind enough to explain how the sed works? I am trying to get to grips with sed and would appreciate the insight.

Thanks for the help Smilie

The perl will get me out of trouble for now, but I'm not sure it is installed on all of our servers so would prefer a sed solution if possible for portability.

Brad
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Tricky Sed

Hello. I am trying to convert occurrences of 'NULL' from a datafile. The 'NULL' occurences appears at this: |NULL| NULL|NULL| NULL|NULL| NULL|NULL| NULL| There should be 52 fields per line. I would like any occurrence of | NULL| or |NULL| to appear as '||' Currently I am using this sed... (2 Replies)
Discussion started by: bestbuyernc
2 Replies

2. UNIX for Dummies Questions & Answers

Sed-- command help required

Hi Gurus, I have a small requirement. Let suppose i have a file test.txt test.txt contains Dispatched date = '2008-04-08' Name = 'Logers' Now i want to add one more line to it as Number of Responses = "$a" $a will be chnaging dynamically which i had grepped it in the script. Now i... (6 Replies)
Discussion started by: pssandeep
6 Replies

3. Shell Programming and Scripting

Help in sed required.

Hi All, I am facing a small problem in sed. I want to insert a line in the existing file. Existing code: access to attr=userPassword by self write by * auth access to * by self write by users read by anonymous auth Desired code: access to attr=userPassword by self... (14 Replies)
Discussion started by: nua7
14 Replies

4. Shell Programming and Scripting

Help required in sed or awk.

Hi All, I need to pick up data on both sides of "=" sign. For eg, following is the context that I have. 125.156.125.147=machine1 147.125.185.156=machine2 147.125.185.159=machine3 Can I have the ip address in one variable and machine name in another variable using sed or awk. ... (1 Reply)
Discussion started by: nua7
1 Replies

5. Shell Programming and Scripting

Help required with awk/sed

Hi I have a file, with format like: column1|coulumn2|column3|column4 A|X|K|18 L|O|R|31,42,25 G|H|I|55,66 L|E|Q|25,31,94 output required: column1|coulumn2|column3|column4 A|X|K|18 L|O|R|31,25 L|E|Q|25,31 Input File Format: All columns are seperated using |, last column... (8 Replies)
Discussion started by: New to awk
8 Replies

6. Shell Programming and Scripting

Tricky sed or awk question

Hello everyone, unfortunately I am no unix nor scripting guru, which is why I am asking for help here. I am trying to reformat a .csv file using sed or awk which has the following format: a,b,C-D-E,f,g h,i,J,k,l m,n,O-P-Q-R-S,t,u v,w,X-Y,z,a It's basically a 5-field text file which has an... (7 Replies)
Discussion started by: awayand
7 Replies

7. Shell Programming and Scripting

Another tricky sed or awk question

This post is in reference to https://www.unix.com/shell-programming-scripting/137977-tricky-sed-awk-question-post302428154.html#post302428154 I am trying to go the opposite direction now: I have the following file: a,b,C,f,g a,b,D,f,g a,b,E,f,g h,i,J,k,l m,n,O,t,u m,n,P,t,u m,n,Q,t,u... (3 Replies)
Discussion started by: awayand
3 Replies

8. Shell Programming and Scripting

sed tricky problem

Hi, I have a file which contains two strings: AAAAA and BBBBB I have two variables in my script: DATE="03/21/2010" aDate="20100321" I need to replace string AAAAA with variable $DATE and BBBBB with $aDate. Here is what I do sed "s/AAAAA/$DATE/" $BASIC_TMPLT | sed "s/BBBBB/$aDate/" >... (4 Replies)
Discussion started by: axed
4 Replies

9. Shell Programming and Scripting

sed help required

Hi All, I have one file with below type of data in it, $ cat test.txt ###123 ###xyxytuerwb ###2 ###tyupe Here I would like to replace all the characters with "x" after the 3 "###" with the same number of characters. Can you please help me to achieve this. (7 Replies)
Discussion started by: gr8_usk
7 Replies

10. UNIX for Dummies Questions & Answers

Clarification required on sed

Hi Can some one tell what does this sed command do sed 's/*$//g I am more curious on the highlighted part , can some one explain what does that mean. Thanks Sri (1 Reply)
Discussion started by: Sri3001
1 Replies
Tcl_GetStdChannel(3)                                          Tcl Library Procedures                                          Tcl_GetStdChannel(3)

__________________________________________________________________________________________________________________________________________________

NAME
Tcl_GetStdChannel, Tcl_SetStdChannel - procedures for retrieving and replacing the standard channels SYNOPSIS
#include <tcl.h> Tcl_Channel Tcl_GetStdChannel(type) Tcl_SetStdChannel(channel, type) ARGUMENTS
int type (in) The identifier for the standard channel to retrieve or modify. Must be one of TCL_STDIN, TCL_STDOUT, or TCL_STDERR. Tcl_Channel channel (in) The channel to use as the new value for the specified standard channel. _________________________________________________________________ DESCRIPTION
Tcl defines three special channels that are used by various I/O related commands if no other channels are specified. The standard input channel has a channel name of stdin and is used by read and gets. The standard output channel is named stdout and is used by puts. The standard error channel is named stderr and is used for reporting errors. In addition, the standard channels are inherited by any child processes created using exec or open in the absence of any other redirections. The standard channels are actually aliases for other normal channels. The current channel associated with a standard channel can be retrieved by calling Tcl_GetStdChannel with one of TCL_STDIN, TCL_STDOUT, or TCL_STDERR as the type. The return value will be a valid channel, or NULL. A new channel can be set for the standard channel specified by type by calling Tcl_SetStdChannel with a new channel or NULL in the channel argument. If the specified channel is closed by a later call to Tcl_Close, then the corresponding standard channel will automatically be set to NULL. If a non-NULL value for channel is passed to Tcl_SetStdChannel, then that same value should be passed to Tcl_RegisterChannel, like so: Tcl_RegisterChannel(NULL, channel); This is a workaround for a misfeature in Tcl_SetStdChannel that it fails to do some reference counting housekeeping. This misfeature can- not be corrected without contradicting the assumptions of some existing code that calls Tcl_SetStdChannel. If Tcl_GetStdChannel is called before Tcl_SetStdChannel, Tcl will construct a new channel to wrap the appropriate platform-specific stan- dard file handle. If Tcl_SetStdChannel is called before Tcl_GetStdChannel, then the default channel will not be created. If one of the standard channels is set to NULL, either by calling Tcl_SetStdChannel with a NULL channel argument, or by calling Tcl_Close on the channel, then the next call to Tcl_CreateChannel will automatically set the standard channel with the newly created channel. If more than one standard channel is NULL, then the standard channels will be assigned starting with standard input, followed by standard out- put, with standard error being last. See Tcl_StandardChannels for a general treatise about standard channels and the behaviour of the Tcl library with regard to them. SEE ALSO
Tcl_Close(3), Tcl_CreateChannel(3), Tcl_Main(3), tclsh(1) KEYWORDS
standard channel, standard input, standard output, standard error Tcl 7.5 Tcl_GetStdChannel(3)
All times are GMT -4. The time now is 02:38 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy