Sponsored Content
Full Discussion: How to replace word in CSV
Top Forums Shell Programming and Scripting How to replace word in CSV Post 302188897 by Franklin52 on Thursday 24th of April 2008 01:24:35 PM
Old 04-24-2008
Try:

Code:
awk '
BEGIN{FS=OFS=","}
NR==FNR{arr[$1]=$2;next}           # Create an associative array using the fields of the 1st file
/Documentation/{split($9,a,"-")    # Search for lines with pattern and create an array to extract the value in a[3]
if(a[3] in arr){$11=arr[a[3]]}}    # If field 11 is in array a replace value
1' "conf.file" "port.csv"          # Print the line

You should have a read of an awk book or tutorial.

Regards
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace a word after a particular word in a file

Hi, I want to replace a word in a file which occurs after a particular word. For example : $cat file.txt CASE WHEN AND c1 = 'I' AND c2= '2' THEN 1 WHEN AND c1= 'I' AND c2= '0' THEN 2 So in this example i want to replace... (4 Replies)
Discussion started by: ashwin3086
4 Replies

2. Shell Programming and Scripting

How to replace a word with another word

Hello Friends, How to substitue with a word by another word in file written in VI Editor. Thanks & Regards Siva Ranganath 7760774961 (2 Replies)
Discussion started by: sivaranganath
2 Replies

3. Shell Programming and Scripting

Replace a word in a string starting with another word

Hi All, I have a file in which a number of lines are starting with similar first word but different next words. I want to replace the any nth word(not 1st or 2nd) with another word. Eg:- My file contains are like this:- Ram is a boy. Ram is a good boy. Ram plays cricket. Here I want to... (2 Replies)
Discussion started by: mukeshbaranwal
2 Replies

4. Shell Programming and Scripting

Find and replace a word in all the files (that contain the word) under a directory

Hi Everyone, I am looking for a simple way for replacing all the files under a directory that use the server "xsgd1234dap" with "xsdr3423pap". For Example: In the Directory, $pwd /home/nick $ grep -l "xsgd1234dap" *.sh | wc -l 119 I have "119" files that are still using... (5 Replies)
Discussion started by: filter
5 Replies

5. Shell Programming and Scripting

How to replace the word?

Hi Everybody, I am having a query like I want to change only first three patterns of the first line in a file. ex: I like unix unix unix unix is very much. after using the command it should be like I like linux linux linux unix is very much. Thanks, Naga (3 Replies)
Discussion started by: nagraju.allam
3 Replies

6. Shell Programming and Scripting

Count characters in a csv file and add an word.

Hello, I want to add a sentence to "post column" those who are only less than 30 characters.Thank you very much for your help. "category","title","post" "Z","Zoo","test 54325 test 45363mc." "Z","Zen","rs2w3rsj 2d342dg 2d3s4f23 d23423s23h 2s34s2423g ds232d34 2342." "Z","Zet","test4444... (3 Replies)
Discussion started by: hoo
3 Replies

7. UNIX for Dummies Questions & Answers

Word Wrap .CSV Fils

Is there a generic method for applying word wrap to all cells for a .csv file? (6 Replies)
Discussion started by: jimmyf
6 Replies

8. Shell Programming and Scripting

Shell Script @ Find a key word and If the key word matches then replace next 7 lines only

Hi All, I have a XML file which is looks like as below. <<please see the attachment >> <?xml version="1.0" encoding="UTF-8"?> <esites> <esite> <name>XXX.com</name> <storeId>10001</storeId> <module> ... (4 Replies)
Discussion started by: Rajeev_hbk
4 Replies

9. Shell Programming and Scripting

Find every alternate word in a csv

Hi, This should be really simple. But not sure why I am unable to crack it. I am looking for a simple one liner to print every alternate word in a csv. say my file is having content : abc,def,ghi,jkl,..... i need the output as below abc ghi (7 Replies)
Discussion started by: ctrld
7 Replies

10. Shell Programming and Scripting

How do i replace a word ending with "key" using awk excpet for one word?

echo {mbr_key,grp_key,dep_key,abc,xyz,aaa,ccc} | awk 'gsub(/^|abc,|$/,"") {print}' Required output {grp_key,xyz,aaa,ccc} (5 Replies)
Discussion started by: 100bees
5 Replies
STREAM_CONTEXT_CREATE(3)						 1						  STREAM_CONTEXT_CREATE(3)

stream_context_create - Creates a stream context

SYNOPSIS
resource stream_context_create ([array $options], [array $params]) DESCRIPTION
Creates and returns a stream context with any options supplied in $options preset. PARAMETERS
o $options - Must be an associative array of associative arrays in the format $arr['wrapper']['option'] = $value. Default to an empty array. o $params - Must be an associative array in the format $arr['parameter'] = $value. Refer to context parameters for a listing of standard stream parameters. RETURN VALUES
A stream context resource. CHANGELOG
+--------+---------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------+ | 5.3.0 | | | | | | | Added the optional $params argument. | | | | +--------+---------------------------------------+ EXAMPLES
Example #1 Using stream_context_create(3) <?php $opts = array( 'http'=>array( 'method'=>"GET", 'header'=>"Accept-language: en " . "Cookie: foo=bar " ) ); $context = stream_context_create($opts); /* Sends an http request to www.example.com with additional headers shown above */ $fp = fopen('http://www.example.com', 'r', false, $context); fpassthru($fp); fclose($fp); ?> SEE ALSO
stream_context_set_option(3), Listing of supported wrappers ("Supported Protocols and Wrappers"), Context options ("Context options and parameters"). PHP Documentation Group STREAM_CONTEXT_CREATE(3)
All times are GMT -4. The time now is 04:23 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy