Sponsored Content
Top Forums Shell Programming and Scripting awk match shell variable that contains special characters? Post 302919474 by RudiC on Wednesday 1st of October 2014 12:43:04 PM
Old 10-01-2014
Without modifying the shell variable:
Code:
name="Matthew Lewis (writer)"
awk -v na="$name" 'BEGIN {gsub(/\(|\)/,"\\\&", na)} $0 ~ na' file.txt
Matthew Lewis (writer)

This User Gave Thanks to RudiC For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk/sed with special characters

i have this script that searches for a pattern. However it fails if the pattern includes some special characters. So far, it fails with the following strings: 1. -Cr 2. $Mj 3. H'412 would a sed or awk be more effective? i don't want the users to put the (\) during the search (they... (5 Replies)
Discussion started by: apalex
5 Replies

2. Shell Programming and Scripting

Variable Manimpulation - special characters

Hello- I have a variables that contains a string like this usr/pass@SCHEMA I want to extract the usr/pass part and ignore the SCHEMA part, I tried to use this ${dbconn%%@} and apparently it will not work because @ is a special character. I tried \@ and still no go. Any idea how to solve... (1 Reply)
Discussion started by: Nomaad
1 Replies

3. Shell Programming and Scripting

Special characters in a bash variable in sed

Hello, I am trying the following: echo __CHANGEME__ >> testfile VAR1="&&&" sed -i "s|__CHANGEME__|${VAR1}|" testfile cat testfile This results in testfile containing __CHANGEME____CHANGEME____CHANGEME__ Whereas I want it to result in &&& I understand that if VAR1="\&\&\&" then... (3 Replies)
Discussion started by: linuxnewbeee
3 Replies

4. Shell Programming and Scripting

Sed failing for variable with special characters

This has been covered many times earlier but couldnt figure the issue myself. Can you please advise whats wrong on the below code I have a variable with special character ($) and am using that variable to replace another variable in file but however sed is failing to parse it correctly ... (7 Replies)
Discussion started by: sasiharitha
7 Replies

5. UNIX for Dummies Questions & Answers

Environment Variable with Special characters

Hello all, I am facing with a problem of invoking an environment variable. If I use this command : /bin/ls -lt FILE_NM_?(20120515|20120516)??????_sas.sig | head -n1 | awk '{print $9}' It perfectly outputs the desired result. FILE_NM_20120516000000_sas.sig But if I do this:... (8 Replies)
Discussion started by: sethmj
8 Replies

6. Shell Programming and Scripting

Trouble with sed and substituting a string with special characters in variable

Hey guys, I know that title is a mouthful - I'll try to better explain my struggles a little better... What I'm trying to do is: 1. Query a db and output to a file, a list of column data. 2. Then, for each line in this file, repeat these values but wrap them with: ITEM{ ... (3 Replies)
Discussion started by: ampsys
3 Replies

7. Shell Programming and Scripting

A test command parameter is not valid, when special characters are tried to match

Hi I have a scenario where hyphen(-) from file should be ignored I used the following code if && ; then if ; then pow=$LINE echo $pow > history.txt flag=1 fi fi I get the following output ./valid.sh: -: 0403-012 A test... (7 Replies)
Discussion started by: Priya Amaresh
7 Replies

8. Shell Programming and Scripting

Parsing special characters from variable commands

Hi, I am fairly new to unix scripting and recently tasked with some reporting scripts. The reporting checks several batch jobs and this is quite iterative. Now I am trying to minimize script effort and maximize reusability as there are only slight nuances in the repetitive tasks. For... (3 Replies)
Discussion started by: joeniks
3 Replies

9. Shell Programming and Scripting

Handle special characters in awk -F

Hello Folks, Need to bisect strings based on a subset. Below works good. echo /a/b/c/d | awk -F"/c/d$" '{print $1}' /a/b However, it goes awry with special characters. echo /a/b/c+/d | awk -F"/c+/d$" '{print $1}' /a/b/c+/d Desired output: /a/b Escaping the special characters... (11 Replies)
Discussion started by: vibhor_agarwali
11 Replies

10. Shell Programming and Scripting

Grep exact match without period or other special characters

If I have a file like the following abc.1 abc abc_1 abc..1 abc*1 abc@1 abc def ghr def...... ddef 5466 def ed def** 123445 I`m trying to find exact words from the list abc def (4 Replies)
Discussion started by: ritakadm
4 Replies
PSERIALIZE(9)						   BSD Kernel Developer's Manual					     PSERIALIZE(9)

NAME
pserialize -- passive serialization mechanism SYNOPSIS
#include <sys/pserialize.h> pserialize_t pserialize_create(void); void pserialize_destroy(pserialize_t psz); int pserialize_read_enter(void); void pserialize_read_exit(int s); void pserialize_perform(pserialize_t psz); DESCRIPTION
Passive serialization is a reader / writer synchronisation mechanism designed for lock-less read operations. The read operations may happen from software interrupt at IPL_SOFTCLOCK. FUNCTIONS
pserialize_create() Allocate a new synchronisation object. pserialize_destroy() Destroy the synchronisation object. No synchronisation activity should happen at this point. pserialize_read_enter() Enter the critical path of the reader side. Returns an IPL value, which must be passed to pserialize_read_exit(9). Protected code path is not allowed to block. pserialize_read_exit() Exit the critical path of the reader side. Takes the IPL value returned by pserialize_read_enter(9). pserialize_perform() Perform the passive serialization on the writer side. Passing of this function ensures that no readers are in action. Writers must be additionally serialized with a separate mechanism, e.g. mutex(9). Operation blocks and it may only be performed from thread context. EXAMPLES
Typical code fragment in the writer side: mutex_enter(&writer_psz_lock); /* * Perform the updates (e.g. remove data items from a list). */ ... pserialize_perform(object->psz); /* * At this point it is safe to destroy old data items. */ mutex_exit(&writer_psz_lock); CODE REFERENCES
The pserialize is implemented within the file sys/kern/subr_pserialize.c. SEE ALSO
membar_ops(3), condvar(9), mutex(9), rwlock(9) Hennessy, et al., Passive serialization in a multitasking environment, US Patent and Trademark Office, US Patent 4809168, February 28, 1989. HISTORY
Passive serialization mechanism first appeared in NetBSD 6.0. BSD
July 30, 2011 BSD
All times are GMT -4. The time now is 08:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy