Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Replace values in a specified column of a file Post 302495831 by Gussifinknottle on Friday 11th of February 2011 10:22:09 AM
Old 02-11-2011
Thank you Ygor for your suggestion.

It works perfectly, except the delimiters gets changed from tab to space. I can post process to change it back; however can it be incorporated in the code itself?

Thanks,
Guss

Quote:
Originally Posted by Ygor
With the given example...
Code:
$ cat file1
100 A 105 B
200 B 205 C
300 C 305 D
400 D 405 E
500 E 505 F

$ awk 'BEGIN{n=split("A B C D E",s);split("1 2 3 4 5",r)}{for(i=1;i<=n;i++)sub(s[i],r[i],$2)};1' file1
100 1 105 B
200 2 205 C
300 3 305 D
400 4 405 E
500 5 505 F

$

 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

replace a column values with the first value in column

Hi All, I have a file which has data in following format: "Body_Model","2/1/2007","2/1/2007" "CSCH74","0","61" "CSCS74","0","647" "CSCX74","0","3" "CSYH74","0","299" "CSYS74","0","2514" "CSYX74","0","3" "Body_Model","3/1/2007","3/1/2007" "CSCH74","0","88" "CSCS74","0","489"... (3 Replies)
Discussion started by: sumeet
3 Replies

2. Shell Programming and Scripting

replace the column values.

I have the below file ...where some of the column values should replaced with desired values ....below file u can find that 3 column where ever 'AAA' comes should replaced with ' CC ' NOTE : we have to pass the column number ,AAA,CC (modified value) as the parameters to the code. ... (6 Replies)
Discussion started by: charandevu
6 Replies

3. Shell Programming and Scripting

Find and replace duplicate column values in a row

I have file which as 12 columns and values like this 1,2,3,4,5 a,b,c,d,e b,c,a,e,f a,b,e,a,h if you see the first column has duplicate values, I need to identify (print it to console) the duplicate value (which is 'a') and also remove duplicate values like below. I could be in two... (5 Replies)
Discussion started by: nuthalapati
5 Replies

4. Shell Programming and Scripting

sed replace values of column with ordered numbering

Hello, I am trying to write a shell script that will create a gnuplot file. My main problem is that I have a data file with two columns: 1.05929120E+09 5.0000701214792 1.05930096E+09 5.00006386985764 1.05930584E+09 5.00019465404908 1.05931072E+09 5.00031960589719 ... (2 Replies)
Discussion started by: pau
2 Replies

5. UNIX for Dummies Questions & Answers

replace a column with values from another file

Dear all, I have a file1.pdb in pdb format and a dat file2 containing values, corresponding to the atoms in the pdb file. these values (file2.dat) need to be in the column instead of the 0.00 (file1) values for each atom in file1.pdb .(the red values must be replaced by the blue ones,in order)... (11 Replies)
Discussion started by: chen.xiao.po
11 Replies

6. Shell Programming and Scripting

Selective Replace awk column values

Hi, I have the following data: 2860377|"DATA1"|"DATA2"|"65343"|"DATA2"|"DATA4"|"11"|"DATA5"|"DATA6"|"65343"|"DATA7"|"0"|"8"|"1"|"NEGATIVE" 32340377|"DATA1"|"DATA2"|"65343"|"DATA2"|"DATA4"|"11"|"DATA5"|"DATA6"|"65343"|"DATA7"|"0"|"8"|"1"|"NEG-DID"... (3 Replies)
Discussion started by: sdohn
3 Replies

7. Shell Programming and Scripting

Replace column values from other file

I have one file as it has the following format File1 S No Site IP Address 1 Australia 192.168.0.1/26 2 Australia 192.168.0.2/26 3 Australia 192.168.0.3/26 I need awk/sed command to replace the column2 value ( under Site) with some other... (8 Replies)
Discussion started by: samaritan
8 Replies

8. UNIX for Dummies Questions & Answers

Replace all decimal values in a column

Hi My input file looks String000002 GeneWise CW 48945 49354 . - 0 Pt=PEQU_00004; String000002 LEN NA 52125 52604 0.945751 - . PID=PEQU_00005;lvid_id=PEQ_28708; String000002 LEN CW 52125 52604 . - 0 ... (3 Replies)
Discussion started by: siya@
3 Replies

9. Shell Programming and Scripting

Trying to get an awk script to replace values in column

I'm trying to make an awk script to compare values I've set as var1, var2, and var3 earlier in the script to the values in the userinputted column of four text files called Node1.txt, Node2.txt, Node3.txt, and Node4.txt and then replace the values in that userinputted column with either ttt or gcc,... (8 Replies)
Discussion started by: Eric1
8 Replies

10. UNIX for Beginners Questions & Answers

Replace a numeric values in a certain column

Hi All, I am trying to replace a certain value from one place in a file . In the below file at position 35 I will have 8 I need to modify all 8 in that position to 7 I tried awk '{gsub("8","7",$35)}1' infile > outfile ----> not working sed -i 's/8/7'g' infile --- it is replacing all... (3 Replies)
Discussion started by: arunkumar_mca
3 Replies
httpd_util(3erl)					     Erlang Module Definition						  httpd_util(3erl)

NAME
httpd_util - Miscellaneous utility functions to be used when implementing Erlang Web server API modules. DESCRIPTION
This module provides the Erlang Web Server API module programmer with miscellaneous utility functions. EXPORTS
convert_request_date(DateString) -> ErlDate|bad_date Types DateString = string() ErlDate = {{Year,Month,Date},{Hour,Min,Sec}} Year = Month = Date = Hour = Min = Sec = integer() convert_request_date/1 converts DateString to the Erlang date format. DateString must be in one of the three date formats that is defined in the RFC 2616. create_etag(FileInfo) -> Etag Types FileInfo = file_info() Etag = string() create_etag/1 calculates the Etag for a file, from its size and time for last modification. fileinfo is a record defined in ker- nel/include/file.hrl decode_hex(HexValue) -> DecValue Types HexValue = DecValue = string() Converts the hexadecimal value HexValue into its decimal equivalent ( DecValue ). day(NthDayOfWeek) -> DayOfWeek Types NthDayOfWeek = 1-7 DayOfWeek = string() day/1 converts the day of the week ( NthDayOfWeek ) as an integer (1-7) to an abbreviated string, that is: 1 = "Mon", 2 = "Tue", ..., 7 = "Sat". flatlength(NestedList) -> Size Types NestedList = list() Size = integer() flatlength/1 computes the size of the possibly nested list NestedList . Which may contain binaries. hexlist_to_integer(HexString) -> Number Types Number = integer() HexString = string() hexlist_to_integer Convert the Hexadecimal value of HexString to an integer. integer_to_hexlist(Number) -> HexString Types Number = integer() HexString = string() integer_to_hexlist/1 Returns a string that represents the Number in a Hexadecimal form. lookup(ETSTable,Key) -> Result lookup(ETSTable,Key,Undefined) -> Result Types ETSTable = ets_table() Key = term() Result = term() | undefined | Undefined Undefined = term() lookup extracts {Key,Value} tuples from ETSTable and returns the Value associated with Key . If ETSTable is of type bag only the first Value associated with Key is returned. lookup/2 returns undefined and lookup/3 returns Undefined if no Value is found. lookup_mime(ConfigDB,Suffix) lookup_mime(ConfigDB,Suffix,Undefined) -> MimeType Types ConfigDB = ets_table() Suffix = string() MimeType = string() | undefined | Undefined Undefined = term() lookup_mime returns the mime type associated with a specific file suffix as specified in the mime.types file (located in the config directory ). lookup_mime_default(ConfigDB,Suffix) lookup_mime_default(ConfigDB,Suffix,Undefined) -> MimeType Types ConfigDB = ets_table() Suffix = string() MimeType = string() | undefined | Undefined Undefined = term() lookup_mime_default returns the mime type associated with a specific file suffix as specified in the mime.types file (located in the config directory ). If no appropriate association can be found the value of DefaultType is returned. message(StatusCode,PhraseArgs,ConfigDB) -> Message Types StatusCode = 301 | 400 | 403 | 404 | 500 | 501 | 504 PhraseArgs = term() ConfigDB = ets_table Message = string() message/3 returns an informative HTTP 1.1 status string in HTML. Each StatusCode requires a specific PhraseArgs : 301 : string() : A URL pointing at the new document position. 400 | 401 | 500 : none (No PhraseArgs ) 403 | 404 : string() : A Request-URI as described in RFC 2616. 501 : {Method,RequestURI,HTTPVersion} : The HTTP Method , Request-URI and HTTP-Version as defined in RFC 2616. 504 : string() : A string describing why the service was unavailable. month(NthMonth) -> Month Types NthMonth = 1-12 Month = string() month/1 converts the month NthMonth as an integer (1-12) to an abbreviated string, that is: 1 = "Jan", 2 = "Feb", ..., 12 = "Dec". multi_lookup(ETSTable,Key) -> Result Types ETSTable = ets_table() Key = term() Result = [term()] multi_lookup extracts all {Key,Value} tuples from an ETSTable and returns all Values associated with the Key in a list. reason_phrase(StatusCode) -> Description Types StatusCode = 100| 200 | 201 | 202 | 204 | 205 | 206 | 300 | 301 | 302 | 303 | 304 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 410 411 | 412 | 413 | 414 415 | 416 | 417 | 500 | 501 | 502 | 503 | 504 | 505 Description = string() reason_phrase returns the Description of an HTTP 1.1 StatusCode , for example 200 is "OK" and 201 is "Created". Read RFC 2616 for further information. rfc1123_date() -> RFC1123Date rfc1123_date({{YYYY,MM,DD},{Hour,Min,Sec}}}) -> RFC1123Date Types YYYY = MM = DD = Hour = Min =Sec = integer() RFC1123Date = string() rfc1123_date/0 returns the current date in RFC 1123 format. rfc_date/1 converts the date in the Erlang format to the RFC 1123 date format. split(String,RegExp,N) -> SplitRes Types String = RegExp = string() SplitRes = {ok, FieldList} | {error, errordesc()} Fieldlist = [string()] N = integer split/3 splits the String in N chunks using the RegExp . split/3 is is equivalent to regexp:split/2 with one exception, that is N defines the number of maximum number of fields in the FieldList . split_script_path(RequestLine) -> Splitted Types RequestLine = string() Splitted = not_a_script | {Path, PathInfo, QueryString} Path = QueryString = PathInfo = string() split_script_path/1 is equivalent to split_path/1 with one exception. If the longest possible path is not a regular, accessible and executable file not_a_script is returned. split_path(RequestLine) -> {Path,QueryStringOrPathInfo} Types RequestLine = Path = QueryStringOrPathInfo = string() split_path/1 splits the RequestLine in a file reference ( Path ) and a QueryString or a PathInfo string as specified in RFC 2616. A QueryString is isolated from the Path with a question mark ( ? ) and PathInfo with a slash (/). In the case of a QueryString , everything before the ? is a Path and everything after a QueryString . In the case of a PathInfo the RequestLine is scanned from left-to-right on the hunt for longest possible Path being a file or a directory. Everything after the longest possible Path , iso- lated with a / , is regarded as PathInfo . The resulting Path is decoded using decode_hex/1 before delivery. strip(String) -> Stripped Types String = Stripped = string() strip/1 removes any leading or trailing linear white space from the string. Linear white space should be read as horizontal tab or space. suffix(FileName) -> Suffix Types FileName = Suffix = string() suffix/1 is equivalent to filename:extension/1 with one exception, that is Suffix is returned without a leading dot ( . ). SEE ALSO
httpd(3erl) Ericsson AB inets 5.5.2 httpd_util(3erl)
All times are GMT -4. The time now is 04:21 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy