Sponsored Content
Full Discussion: awk gsub
Top Forums Shell Programming and Scripting awk gsub Post 302727679 by rdrtx1 on Tuesday 6th of November 2012 03:46:06 PM
Old 11-06-2012
gsub returns the number of matches. In the example, the unquoted result is stored in variable f.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

use var in gsub of awk

Hi all, This problem has cost me half a day, and i still do not know how to do. Any help will be appreciated. Thanks advance. I want to use a variable as the first parameters of gsub function of awk. Example: { ... arri]=gsub(i,tolower(i),$1) (which should be ambraced by //) ... } (1 Reply)
Discussion started by: summer_cherry
1 Replies

2. Shell Programming and Scripting

Help with AWK and gsub

Hello, I have a variable that displays the following results from a JVM.... 1602100K->1578435K I would like to collect the value of 1578435 which is the value after a garbage collection. I've tried the following command but it looks like I can't get the > to work. Any suggestions as... (4 Replies)
Discussion started by: npolite
4 Replies

3. Shell Programming and Scripting

awk gsub

Hi all I want to do a simple substitution in awk but I am getting unexpected output. My function accepts a time and then prints out a validation message if the time is valid. However some times may include a : and i want to strip this out if it exists before i get to the validation. I have shown... (4 Replies)
Discussion started by: pxy2d1
4 Replies

4. Shell Programming and Scripting

Awk Gsub Query

Hi, Can some one please explain the following line please throw some light on the ones marked in red awk '{print $9}' ${FTP_LOG} | awk -v start=${START_DATE} 'BEGIN { FS = "." } { old_line1=$0; gsub(/\-/,""); if ( $3 >= start ) print old_line1 }' | awk -v end=${END_DATE} 'BEGIN { FS="." } {... (3 Replies)
Discussion started by: crosairs
3 Replies

5. Shell Programming and Scripting

Awk gsub error.

I want to replace comma with space and "*646#" with space. I am using the following code: nawk -F"|" '{gsub(","," ",$3); gsub(/\*646\#/"," ",$3);print}' OFS="|" file I am getting following error: Help is appreciated (5 Replies)
Discussion started by: pinnacle
5 Replies

6. Shell Programming and Scripting

Help with awk and gsub using C shell

Being new to awk, I am still running into little stupid things. For this issues I am trying to search for all occurrences of a string in a file and replace all of those occurrences with a replacement string. I tried doing awk '{gsub("|750101|", "|000000|", $0)}' infile > outfile Unix... (3 Replies)
Discussion started by: jclanc8
3 Replies

7. Shell Programming and Scripting

awk gsub with variables?

Hey, I would like to replace a string by a new one. Teh problem is that both strings should be variables to be flexible, because I am having a lot of files (with the same structure, but in different folders) for i in daysim_* do cd $i/5/ folder=`pwd |awk '{print $1}'` awk '{ if... (3 Replies)
Discussion started by: ergy1983
3 Replies

8. Shell Programming and Scripting

Awk; gsub in fields 3 and 4

I want to transform a log file into input for a database. Here's the log file: Tue Aug 4 20:17:01 PDT 2009 Wireless users: 339 Daily Average: 48.4285 = Tue Aug 11 20:17:01 PDT 2009 Wireless users: 295 Daily Average: 42.1428 = Tue Aug 18 20:17:01 PDT 2009 Wireless users: 294 Daily... (6 Replies)
Discussion started by: Bubnoff
6 Replies

9. UNIX for Dummies Questions & Answers

awk gsub with variables

Hello, I'm trying to substitute a string with leading zero for all the records except the trailer record using awk command and with variables. The input file test_med1.txt has data like below 1234ABC...........................9200............LF... (2 Replies)
Discussion started by: somu_june
2 Replies

10. Shell Programming and Scripting

Gsub function in awk

Hello, I had some difficulty to understand the gsub function and maybe the regex in this script to remove all the punctuations: awk 'gsub(//, " ", $0)' text.txtFile text.txt: This is a test for gsub I typed this random text file which contains punctuation like ,.;!'"?/\ etc. The script... (6 Replies)
Discussion started by: yifangt
6 Replies
wordexp(3C)						   Standard C Library Functions 					       wordexp(3C)

NAME
wordexp, wordfree - perform word expansions SYNOPSIS
#include <wordexp.h> int wordexp(const char *restrict words, wordexp_t *restrict pwordexp, int flags); void wordfree(wordexp_t *pwordexp); DESCRIPTION
The wordexp() function performs word expansions, subject to quoting, and places the list of expanded words into the structure pointed to by pwordexp. The wordfree() function frees any memory allocated by wordexp() associated with pwordexp. words Argument The words argument is a pointer to a string containing one or more words to be expanded. The expansions will be the same as would be per- formed by the shell if words were the part of a command line representing the arguments to a utility. Therefore, words must not contain an unquoted NEWLINE or any of the unquoted shell special characters: | & ; < > except in the context of command substitution. It also must not contain unquoted parentheses or braces, except in the context of command or variable substitution. If the argument words contains an unquoted comment character (number sign) that is the beginning of a token, word- exp() may treat the comment character as a regular character, or may interpret it as a comment indicator and ignore the remainder of words. pwordexp Argument The structure type wordexp_t is defined in the header <wordexp.h> and includes at least the following members: size_t we_wordc Count of words matched by words. char **we_wordv Pointer to list of expanded words. size_t we_offs Slots to reserve at the beginning of pwordexp->we_wordv. The wordexp() function stores the number of generated words into pwordexp->we_wordc and a pointer to a list of pointers to words in pword- exp->we_wordv. Each individual field created during field splitting is a separate word in the pwordexp->we_wordv list. The words are in order. The first pointer after the last word pointer will be a null pointer. It is the caller's responsibility to allocate the storage pointed to by pwordexp. The wordexp() function allocates other space as needed, including memory pointed to by pwordexp->we_wordv. The wordfree() function frees any memory associated with pwordexp from a previous call to wordexp(). flags Argument The flags argument is used to control the behavior of wordexp(). The value of flags is the bitwise inclusive OR of zero or more of the fol- lowing constants, which are defined in <wordexp.h>: WRDE_APPEND Append words generated to the ones from a previous call to wordexp(). WRDE_DOOFFS Make use of pwordexp->we_offs. If this flag is set, pwordexp->we_offs is used to specify how many NULL pointers to add to the beginning of pwordexp->we_wordv. In other words, pwordexp->we_wordv will point to pwordexp->we_offs NULL pointers, fol- lowed by pwordexp->we_wordc word pointers, followed by a NULL pointer. WRDE_NOCMD Fail if command substitution is requested. WRDE_REUSE The pwordexp argument was passed to a previous successful call to wordexp(), and has not been passed to wordfree(). The result will be the same as if the application had called wordfree() and then called wordexp() without WRDE_REUSE. WRDE_SHOWERR Do not redirect stderr to /dev/null. WRDE_UNDEF Report error on an attempt to expand an undefined shell variable. The WRDE_APPEND flag can be used to append a new set of words to those generated by a previous call to wordexp(). The following rules apply when two or more calls to wordexp() are made with the same value of pwordexp and without intervening calls to wordfree(): 1. The first such call must not set WRDE_APPEND. All subsequent calls must set it. 2. All of the calls must set WRDE_DOOFFS, or all must not set it. 3. After the second and each subsequent call, pwordexp->we_wordv will point to a list containing the following: a. zero or more NULL pointers, as specified by WRDE_DOOFFS and pwordexp->we_offs. b. pointers to the words that were in the pwordexp->we_wordv list before the call, in the same order as before. c. pointers to the new words generated by the latest call, in the specified order. 4. The count returned in pwordexp->we_wordc will be the total number of words from all of the calls. 5. The application can change any of the fields after a call to wordexp(), but if it does it must reset them to the original value before a subsequent call, using the same pwordexp value, to wordfree() or wordexp() with the WRDE_APPEND or WRDE_REUSE flag. If words contains an unquoted: NEWLINE | & ; < > ( ) { } in an inappropriate context, wordexp() will fail, and the number of expanded words will be zero. Unless WRDE_SHOWERR is set in flags, wordexp() will redirect stderr to /dev/null for any utilities executed as a result of command substi- tution while expanding words. If WRDE_SHOWERR is set, wordexp() may write messages to stderr if syntax errors are detected while expanding words. If WRDE_DOOFFS is set, then pwordexp-> we_offs must have the same value for each wordexp() call and wordfree() call using a given pwordexp. The following constants are defined as error return values: WRDE_BADCHAR One of the unquoted characters: NEWLINE | & ; < > ( ) { } appears in words in an inappropriate context. WRDE_BADVAL Reference to undefined shell variable when WRDE_UNDEF is set in flags. WRDE_CMDSUB Command substitution requested when WRDE_NOCMD was set in flags. WRDE_NOSPACE Attempt to allocate memory failed. WRDE_SYNTAX Shell syntax error, such as unbalanced parentheses or unterminated string. RETURN VALUES
On successful completion, wordexp() returns 0. Otherwise, a non-zero value as described in <wordexp.h> is returned to indicate an error. If wordexp() returns the value WRDE_NOSPACE, then pwordexp->we_wordc and pwordexp->we_wordv will be updated to reflect any words that were successfully expanded. In other cases, they will not be modified. The wordfree() function returns no value. ERRORS
No errors are defined. USAGE
This function is intended to be used by an application that wants to do all of the shell's expansions on a word or words obtained from a user. For example, if the application prompts for a filename (or list of filenames) and then uses wordexp() to process the input, the user could respond with anything that would be valid as input to the shell. The WRDE_NOCMD flag is provided for applications that, for security or other reasons, want to prevent a user from executing shell command. Disallowing unquoted shell special characters also prevents unwanted side effects such as executing a command or writing a file. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ SEE ALSO
fnmatch(3C), glob(3C), attributes(5), standards(5) SunOS 5.10 1 Nov 2003 wordexp(3C)
All times are GMT -4. The time now is 03:03 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy