Sponsored Content
Full Discussion: Awk to replace a field
Top Forums Shell Programming and Scripting Awk to replace a field Post 302416239 by sugan on Sunday 25th of April 2010 10:28:28 PM
Old 04-25-2010
Awk to replace a field

Hi
I am using awk to replace the 4th feild of the input line. My code is below:

Code:
REP_LINE=$(echo $Line | awk -v var=$REPL_DT '{$4=var; print}')

It does replaces but all words/phrases after the 4th feild are erased. Is there a way to modify the 4th feild of the input line and to have all words/pharases that comes after the 4th feild.

For ex:
Code:
# ID          Owner       Last Reset Date
# JPN7386     Cindy       2010/03/17 (should be same as FIW-LR AP)

Here the script replace the Last reset date (4th feild) but all words following the 4th field, (should be same as FIW-LR AP) gets erased.

Thanks,
Sugan
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk: find and replace in certain field only, help needed

I got a sample file like this. $ cat test 12|13|100|s 12|13|100|s 100|13|100|s 12|13|100|s I want to replace all 100 by 2000 only in 3rd field using "awk" This is replacing all 100's :-( $ awk -F "|" '{gsub( /100/,"2000");print}' test 12|13|2000|s 12|13|2000|s 2000|13|2000|s... (5 Replies)
Discussion started by: jkl_jkl
5 Replies

2. Shell Programming and Scripting

awk to replace particular field

i have bad data for instance, the use of capital letters in the middle of the word. I identified the errors, made a list and put it in a file error_correction.txt Incorrect,Correct VeNOM,Venom nos,NOS . . . My data file looks like this: vgr,bugatti veron,,3.5,Venom,6,.......,....... (14 Replies)
Discussion started by: VGR
14 Replies

3. Shell Programming and Scripting

awk search and replace field

I am writing a c++ program that has many calls of pow(input,2). I now realize that this is slowing down the program and these all should be input * input for greater speed. There should be a simple way of doing this replacement throughout my file with awk, but I am not very familiar with awk.... (2 Replies)
Discussion started by: bluejayek
2 Replies

4. Shell Programming and Scripting

awk how to replace specific field with new value

I need to replace specific field (x) in a table with new value (y): Input: 1 2 3 4 5 x 6 7 8 9 0 0 Output: 1 2 3 4 5 y 6 7 8 9 0 0 I have no idea how to do this. (10 Replies)
Discussion started by: setepo
10 Replies

5. Shell Programming and Scripting

AWK How to replace a field using 2 shell variables?

Hello everybody: I want to replace any field $2 of any file line (f.i. test.txt) matching $1 with a shell variable. $ cat test.txt F 0 B A H -12.33 Now I'm going to ask the value of variable B: $ SEARCHVAR=B $ OLDVAL=$(awk -v SEARCHVAR="$SEARCHVAR"... (4 Replies)
Discussion started by: basalt
4 Replies

6. Shell Programming and Scripting

awk search and replace in a targeted field instead of $0

Hi I would like to apply this gawk command: gawk '{$0=gensub(/\y+\y/,"","g"); print}' file not to the whole $0 but just to the part of $0 that is between: (a number)"> and </mrk> Is it possible? thanks for your help. (4 Replies)
Discussion started by: louisJ
4 Replies

7. Shell Programming and Scripting

AWK replace one field

I have some problem with this. Need to change field #3 to 5 if field #1 = A and filed #2 =B DataA C 6 T C B 4 R A B 3 T D E 5 4 I would like to do two things if statement is true, but can not get it to work. Here it prints column #3 if statement is true, and this works awk '{if... (3 Replies)
Discussion started by: Jotne
3 Replies

8. Shell Programming and Scripting

Need an awk script to calculate the percentage of value field and replace

Need an awk script to calculate the percentage of value field and replace I have a input file called file.txt with the following content: john|622.5674603562933|8|br:1;cn:3;fr:1;jp:1;us:2 andy|0.0|12|**:3;br:1;ca:2;de:2;dz:1;fr:2;nl:1 in fourth filed of input file, calulate percentage of each... (1 Reply)
Discussion started by: veeruasu
1 Replies

9. Shell Programming and Scripting

awk Match First Field and Replace Second Column

Hi Friends, I have looked around the forums and over online but couldn't figure out how to deal with this problem input.txt gene1,axis1/0/1,axis2/0/1 gene1,axis1/1/2,axis2/1/2 gene1,axis1/2/3,axis2/2/3 gene2,axis1/3/4,axis2/3/4 Match on first column and if first column is... (1 Reply)
Discussion started by: jacobs.smith
1 Replies

10. Shell Programming and Scripting

awk to replace a specific field in certain condition

Hi, I have a file like below PRUM,67016800 ,CC ,C1,67016800 , ,Y,Y,2 ,CK,BX,FOX ,00000001,EA,00000001,20141120 00:00:00, ,N,Y,Y,CK ABCDEF... (7 Replies)
Discussion started by: mady135
7 Replies
BEASTIE.4TH(8)						    BSD System Manager's Manual 					    BEASTIE.4TH(8)

NAME
beastie.4th -- FreeBSD ASCII art boot module DESCRIPTION
The file that goes by the name of beastie.4th is a set of commands designed to draw the ASCII art FreeBSD mascot -- known simply as beastie -- to the right of the boot loader menu. The commands of beastie.4th by themselves are not enough for most uses. Please refer to the exam- ples below for the most common situations, and to loader(8) for additional commands. Before using any of the commands provided in beastie.4th, it must be included through the command: include beastie.4th This line is present in the default /boot/loader.rc file, so it is not needed (and should not be re-issued) in a normal setup. The commands provided by it are: draw-beastie Draws the FreeBSD logo. The logo that is drawn is configured by setting the loader_logo variable in loader.conf(5) to one of ``beastie'', ``beastiebw'', ``fbsdbw'', ``orb'', and ``orbbw'' (the default). The position of the logo can be configured by setting the loader_logo_x and loader_logo_y variables in loader.conf(5). The default values are 46 (x) and 4 (y). clear-beastie Clears the screen of beastie. beastie-start Initializes the interactive boot loader menu. The loader_delay variable can be configured in loader.conf(5) to the number of seconds you would like to delay loading the boot menu. During the delay the user can press Ctrl-C to fall back to autoboot or ENTER to proceed. The default behavior is to not delay. The environment variables that effect its behavior are: loader_logo Selects the desired logo in the beastie boot menu. Possible values are: ``fbsdbw'', ``beastie'', ``beastiebw'', ``orb'', ``orbbw'' (default), and ``none''. loader_logo_x Sets the desired column position of the logo. Default is 46. loader_logo_y Sets the desired row position of the logo. Default is 4. beastie_disable If set to ``YES'', the beastie boot menu will be skipped. The beastie boot menu is always skipped if booting UEFI or running non-x86 hardware. loader_delay If set to a number higher than zero, introduces a delay before starting the beastie boot menu. During the delay the user can press either Ctrl-C to skip the menu or ENTER to proceed to the menu. The default is to not delay when loading the menu. FILES
/boot/loader The loader(8). /boot/beastie.4th beastie.4th itself. /boot/loader.rc loader(8) bootstrapping script. EXAMPLES
Standard i386 /boot/loader.rc: include /boot/beastie.4th beastie-start Set a different logo in loader.conf(5): loader_logo="beastie" SEE ALSO
loader.conf(5), loader(8), loader.4th(8) HISTORY
The beastie.4th set of commands first appeared in FreeBSD 5.1. AUTHORS
The beastie.4th set of commands was written by Scott Long <scottl@FreeBSD.org>, Aleksander Fafula <alex@fafula.com> and Devin Teske <dteske@FreeBSD.org>. BSD
April 27, 2014 BSD
All times are GMT -4. The time now is 04:32 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy