Hi,
I generally use Perl for this
ex.
perl -e 's/pattern/replace/g' -p -i <filename>
I did something like this..
find . -type f -exec perl -e 's/pattern/replace/g' -p -i {} \;
I want to do this with "sed"
but what I get is the output being printed on the screen..
i can do sed... (3 Replies)
I need to remove the '&' from a file.
In each line of the file, the fields are separated by ^K.
I only want to remove '&' if it exists in field number 9. (example of field 9: abc&xyz)
I need to do an in place/in line edit.
So far I have accomplished the following:
awk -F '^K' '{print... (6 Replies)
Col1 Col2 Col3 Col4
12 Completed 08 0830
12 In Progress 09 0829
11 For F U 07 0828
Considering the file above, how could i replace the third column the most efficient way? The actual file size is almost 1G. I am... (10 Replies)
I have the follwoing file:
This looks to be : seperated.
For the first field i want only the file name without ".txt" and also i want to remove "+" sign if the second field starts with "+" sign.
Input file:
Output file:
Appreciate your help (9 Replies)
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)
please help me to edit the second field using awk or sed
i have input file below
aa1001 000001
bb1002 000002
cc1003 000003
so i want the output file like below
aa1001 01
bb1002 02
cc1003 03 (38 Replies)
Hi,
I have file with all the lines as following format
<namebindings:StringNameSpaceBinding xmi:id="StringNameSpaceBinding" name="ENV_CONFIG_PATH" nameInNameSpace="COMP/HOD/MYSTR/BACKOFFICE/ENV_CONFIG_PATH" stringToBind="test"/>
I want to replace (all the lines) value of... (8 Replies)
Hey guys,
I'm trying to learn a bit of awk/sed and I'm using different sites to learn it from, and i think I'm starting to get confused (doesn't take much!).
Anyway, say I have a csv file which has something along the lines of the following in it:"test","127.0.0.1","startup... (6 Replies)
Hi Experts,
I am new to shell scripting. Need some help in doing one task given by the customer.
The sample record in a file is as follows:
3538,,,,,,ID,ID1,,,,,,,,,,,
It needs to be the following:
3538,,353800,353800,,,ID,ID1,,,,,COLX,,,,,COLY,
And i want to modify this record in... (3 Replies)
I'm working on a script to execute a number of items. One being, editing particular files to add certain lines. I'm attempting to utilize sed, but, having issues when running from a bash script. Assistance is greatly appreciated.
My example:
sed -i '14 i\
# add these lines
add these lines to... (5 Replies)
Discussion started by: Nvizn
5 Replies
LEARN ABOUT REDHAT
hdestroy_r
HSEARCH(3) Linux Programmer's Manual HSEARCH(3)NAME
hcreate, hdestroy, hsearch - hash table management
SYNOPSIS
#include <search.h>
int hcreate(size_t nel);
ENTRY *hsearch(ENTRY item, ACTION action);
void hdestroy(void);
#define _GNU_SOURCE
#include <search.h>
int hcreate_r(size_t nel, struct hsearch_data *tab);
int *hsearch_r(ENTRY item, ACTION action, ENTRY **ret, struct hsearch_data *tab);
void hdestroy_r(struct hsearch_data *tab);
DESCRIPTION
The three functions hcreate, hsearch, and hdestroy allow the user to create a hash table (only one at a time) which associates a key with
any data. The three functions hcreate_r, hsearch_r, hdestroy_r are reentrant versions that allow the use of more than one table.
First the table must be created with the function hcreate(). The argument nel is an estimate of the maximum number of entries in the ta-
ble. The function hcreate() may adjust this value upward to improve the performance of the resulting hash table.
The corresponding function hdestroy() frees the memory occupied by the hash table so that a new table can be constructed.
The argument item is of type ENTRY, which is a typedef defined in <search.h> and includes these elements:
typedef struct entry {
char *key;
void *data;
} ENTRY;
The field key points to the NUL-terminated string which is the search key. The field data points to the data associated with that key.
The function hsearch() searches the hash table for an item with the same key as item (where "the same" is determined using strcmp(3)), and
if successful returns a pointer to it. The argument action determines what hsearch() does after an unsuccessful search. A value of ENTER
instructs it to insert a copy of item, while a value of FIND means to return NULL.
RETURN VALUE
hcreate() and hcreate_r() return 0 when allocation of the memory for the hash table fails, nonzero otherwise.
hsearch() returns NULL if action is ENTER and the hash table is full, or action is FIND and item cannot be found in the hash table.
hsearch_r() returns 0 if action is ENTER and the hash table is full, and nonzero otherwise.
ERRORS
ENOMEM Out of memory.
CONFORMS TO
The functions hcreate, hsearch, and hdestroy are from SVID, and are described in POSIX 1003.1-2001. The functions hcreate_r, hsearch_r,
hdestroy_r are GNU extensions.
BUGS
SVID and POSIX 1003.1-2001 specify that action is significant only for unsuccessful searches, so that an ENTER should not do anything for a
successful search. The libc and glibc implementations update the data for the given key in this case.
Individual hash table entries can be added, but not deleted.
EXAMPLE
The following program inserts 24 items in to a hash table, then prints some of them.
#include <stdio.h>
#include <search.h>
char *data[] = { "alpha", "bravo", "charlie", "delta",
"echo", "foxtrot", "golf", "hotel", "india", "juliet",
"kilo", "lima", "mike", "november", "oscar", "papa",
"quebec", "romeo", "sierra", "tango", "uniform",
"victor", "whisky", "x-ray", "yankee", "zulu"
};
int main() {
ENTRY e, *ep;
int i;
/* starting with small table, and letting it grow does not work */
hcreate(30);
for (i = 0; i < 24; i++) {
e.key = data[i];
/* data is just an integer, instead of a
pointer to something */
e.data = (char *)i;
ep = hsearch(e, ENTER);
/* there should be no failures */
if (ep == NULL) {
fprintf(stderr, "entry failed
");
exit(1);
}
}
for (i = 22; i < 26; i++) {
/* print two entries from the table, and
show that two are not in the table */
e.key = data[i];
ep = hsearch(e, FIND);
printf("%9.9s -> %9.9s:%d
", e.key,
ep ? ep->key : "NULL",
ep ? (int)(ep->data) : 0);
}
return 0;
}
SEE ALSO bsearch(3), lsearch(3), tsearch(3), malloc(3)GNU 2001-12-26 HSEARCH(3)