Sponsored Content
Top Forums Shell Programming and Scripting How to replace the 10th column? Post 302938376 by disedorgue on Sunday 15th of March 2015 10:27:58 AM
Old 03-15-2015
Imagine that the keyword1 is "8" , keyword2 is "5" and keyword3 is "6":
Code:
$ awk '$10==24{$10="8"} $10==8{$10="5"} $10==0{$10="6"}1' FS=, OFS=, input.txt 
Col1,Col2,Col3,Col4,Col5,Col6,Col7,Col8,Col9,Col10,Col11,Col12,Col13,Col14,Col15,Col16,Col17
2015/03/14 15:00:04,2015/03/14 15:00:04,0,Server05,Omega-God,Beta_G,101011247,1,1,5,7,0,,339083645,1,1,
2015/03/14 15:13:48,2015/03/14 09:40:38,0,Server04,Omega-God,Beta_G,101011247,5,1,5,7,0,,319207661,1,1,103510841
2015/03/14 15:14:55,2015/03/14 09:40:38,0,Server04,Omega-God,Beta_G,101011247,6,1,5,7,0,,319207661,1,1,
2015/03/14 15:29:56,2015/03/14 09:40:38,0,Server03,Omega-God,Beta_G,101011247,7,1,5,7,0,,319207661,1,1,
2015/03/14 15:50:53,2015/03/14 09:40:38,0,Server04,Omega-God,Beta_G,101011247,8,1,5,7,0,,319207661,1,1,103510841
2015/03/14 18:50:58,2015/03/14 09:40:38,0,Server04,Omega-God,Beta_G,101011247,12,0,6,0,1,1,319207661,1,1,103510841
2015/03/14 18:51:03,2015/03/14 09:40:38,1,Server01,101011247,Server04,Omega-God,1,0,6,0,1,1,347955199,1,1,
2015/03/14 18:51:11,2015/03/14 15:05:19,1,Server04,101011247,Server04,Omega-God,1,0,6,0,1,1,347963352,1,1,

Code:
$ awk -F, 'BEGIN{OFS=FS;A[0]="6";A[8]="5";A[24]="8"};A[$10] ? $10=A[$10] : 1' input.txt 
Col1,Col2,Col3,Col4,Col5,Col6,Col7,Col8,Col9,Col10,Col11,Col12,Col13,Col14,Col15,Col16,Col17
2015/03/14 15:00:04,2015/03/14 15:00:04,0,Server05,Omega-God,Beta_G,101011247,1,1,8,7,0,,339083645,1,1,
2015/03/14 15:13:48,2015/03/14 09:40:38,0,Server04,Omega-God,Beta_G,101011247,5,1,5,7,0,,319207661,1,1,103510841
2015/03/14 15:14:55,2015/03/14 09:40:38,0,Server04,Omega-God,Beta_G,101011247,6,1,8,7,0,,319207661,1,1,
2015/03/14 15:29:56,2015/03/14 09:40:38,0,Server03,Omega-God,Beta_G,101011247,7,1,8,7,0,,319207661,1,1,
2015/03/14 15:50:53,2015/03/14 09:40:38,0,Server04,Omega-God,Beta_G,101011247,8,1,5,7,0,,319207661,1,1,103510841
2015/03/14 18:50:58,2015/03/14 09:40:38,0,Server04,Omega-God,Beta_G,101011247,12,0,6,0,1,1,319207661,1,1,103510841
2015/03/14 18:51:03,2015/03/14 09:40:38,1,Server01,101011247,Server04,Omega-God,1,0,6,0,1,1,347955199,1,1,
2015/03/14 18:51:11,2015/03/14 15:05:19,1,Server04,101011247,Server04,Omega-God,1,0,6,0,1,1,347963352,1,1,

Regards.
This User Gave Thanks to disedorgue For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace 10th column with a new column--- Terriblly hurry

Hi Can any one tell me how to replace the 10th column in a file(comma delimted) with a new file with a single column. Can any one Help me out of the please as soon as possible as i am in a terribley hurry!!!!!! Many THanks, (2 Replies)
Discussion started by: ahmedwaseem2000
2 Replies

2. Shell Programming and Scripting

Replace 10th Field by 2

Hello, I need some help ....i have a file with many number of fields i want to replace the 10th field of the file by number 2 .Also the delimeter of the file is | . Pls suggest and help.. Regards, (2 Replies)
Discussion started by: PradeepRed
2 Replies

3. 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

4. Shell Programming and Scripting

awk/sed column replace using column header - help

$ cat log.txt Name Age Sex Lcation nfld alias xsd CC 25 M XYZ asx KK Y BB 21 F XAS awe SS N SD 21 M AQW rty SD A How can I replace the column with header "Lcation" with the column with header "alias" and delete the "alias" column? so that the final output will become: Name Age Sex... (10 Replies)
Discussion started by: jkl_jkl
10 Replies

5. UNIX and Linux Applications

Replace string in unix from 10th column onwards

Hi All, I need to replace the last 19 bytes of the following string My_Org_Testing_20090102_231124.txt (Text_Date_Time.txt). I would like to derive the current time using "date +%Y%m%d_%H%M%S.txt" and replace the last 19 bytes of the above string I would appreciate if someone could... (3 Replies)
Discussion started by: rpk2008
3 Replies

6. Shell Programming and Scripting

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2 file 1 sample SNDK 80004C101 AT XLNX 983919101 BB NETL 64118B100 BS AMD 007903107 CC KLAC 482480100 DC TER 880770102 KATS ATHR 04743P108 KATS... (7 Replies)
Discussion started by: rydz00
7 Replies

7. Shell Programming and Scripting

Replace column that matches specific pattern, with column data from another file

Can anyone please help with this? I have 2 files as given below. If 2nd column of file1 has pattern foo1@a, find the matching 1st column in file2 & replace 2nd column of file1 with file2's value. file1 abc_1 foo1@a .... abc_1 soo2@a ... def_2 soo2@a .... def_2 foo1@a ........ (7 Replies)
Discussion started by: prashali
7 Replies

8. Shell Programming and Scripting

Get extract and replace column with link in a column where it exists

hi i have sample data a,b,c,d,e,g h http://mysite.xyx z,b,d,f,e,s t http://123124# a,b,c,i,m,nothing d,i,j,e,w,nothing output expected is a,b,c,d,e,http://mysite.xyx z,b,d,f,e,http://123124# a,b,c,i,m,nothing d,i,j,e,w,nothing i can get only links using grep -o 'http.*' i... (8 Replies)
Discussion started by: zozoo
8 Replies

9. Shell Programming and Scripting

Change 10th column formatting.

Hi Experts, I created a powershell script to fetch user details from active directory and export it to a csv/excel. "abc","bcd","devloper;admin" "bcd","dca","tester;QA;admin" So here user abc is member of devloper and admin group and user bcd is a member of tester,QA and admin... (6 Replies)
Discussion started by: shekhar_4_u
6 Replies

10. UNIX for Beginners Questions & Answers

awk script to extract a column, replace one of the header and replace year(from ddmmyy to yyyy)

I have a csv which has lot of columns . I was looking for an awk script which would extract a column twice. for the first occurance the header and data needs to be intact but for the second occurance i want to replace the header name since it a duplicate and extract year value which is in ddmmyy... (10 Replies)
Discussion started by: Kunalcurious
10 Replies
set_color(1)							       fish							      set_color(1)

NAME
set_color - set_color - set the terminal color set_color - set the terminal color Synopsis set_color [-v --version] [-h --help] [-b --background COLOR] [COLOR] Description Change the foreground and/or background color of the terminal. COLOR is one of black, red, green, brown, yellow, blue, magenta, purple, cyan, white and normal. o -b, --background Set the background color o -c, --print-colors Prints a list of all valid color names o -h, --help Display help message and exit o -o, --bold Set bold or extra bright mode o -u, --underline Set underlined mode o -v, --version Display version and exit Calling set_color normal will set the terminal color to whatever is the default color of the terminal. Some terminals use the --bold escape sequence to switch to a brighter color set. On such terminals, set_color white will result in a grey font color, while set_color --bold white will result in a white font color. Not all terminal emulators support all these features. This is not a bug in set_color but a missing feature in the terminal emulator. set_color uses the terminfo database to look up how to change terminal colors on whatever terminal is in use. Some systems have old and incomplete terminfo databases, and may lack color information for terminals that support it. Download and install the latest version of ncurses and recompile fish against it in order to fix this issue. Version 1.23.1 Sun Jan 8 2012 set_color(1)
All times are GMT -4. The time now is 06:48 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy