Sponsored Content
Top Forums Shell Programming and Scripting How to replace a specific word in specific column? Post 302295221 by Shahul on Saturday 7th of March 2009 02:01:24 AM
Old 03-07-2009
Hi,

hope this could help you..

file1:
id host ip location remarks
1 host1 ip1 - xxx
2 host2 ip2 - xxx
3 host3 ip3 - xxx
--
--
9 host9 ip9 - xxx

file2:
host1 location1
host2 location2
host3 location3
--
--
host9 location9


script:
Code:
for f in `sed '1d' file1|awk '{print $2}'`
  do
     echo $f
     value=`awk -v var=$f '{if($1~var) {print $2}}' file2`
              if [ $? -eq 0 ]
                 then
                 awk -v var=$value -v var1=$f  '{if($0~var1){print$1,$2,$3,var,$5}}' file1 |head -1 >> out.lst
                 fi
 done
 
 head -1 file1 > outnew.lst
 cat out.lst >> outnew.lst

output:
id host ip location remarks
1 host1 ip1 location1 xxx
2 host2 ip2 location2 xxx
3 host3 ip3 location3 xxx
9 host9 ip9 location9 xxx


Thanks
Sha
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to cut first line only from a text near a specific column without cutting a word

First I have to say thank you to this community and this forum. You helped me very much builing several useful scripts. Now, I can't get a solution the following problem, I'm stuck somehow. Maybe someone has an idea. In short, I dump a site via lynx and pipe the output in a file. I need to... (7 Replies)
Discussion started by: lowmaster
7 Replies

2. UNIX for Dummies Questions & Answers

How to print line starts with specific word and contains specific word using sed?

Hi, I have gone through may posts and dint find exact solution for my requirement. I have file which consists below data and same file have lot of other data. <MAPPING DESCRIPTION ='' ISVALID ='YES' NAME='m_TASK_UPDATE' OBJECTVERSION ='1'> <MAPPING DESCRIPTION ='' ISVALID ='NO'... (11 Replies)
Discussion started by: tmalik79
11 Replies

3. Shell Programming and Scripting

Help with replace column data with specific word

Input file: Populus_trichocarpa 30 0 50 0 0 US Vitis_vinifera 1 18 2 8 6 US Populus_trichocarpa 1 5 100 0 0 US Arabidopsis_lyrata_subsp._lyrata 0 90 0 0 0 US Glycine_max 0 2 3 0 70 UK Desired output file: Populus_trichocarpa YES NO YES NO NO US Vitis_vinifera YES YES YES YES YES US... (4 Replies)
Discussion started by: perl_beginner
4 Replies

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

5. Shell Programming and Scripting

Using sed to replace a word at specific location

I'm try to change a the prohibit to aix for the lines starting with ssh and emagent and rest should be the same. Can anyone please suggest me how to do that using a shell script or sed passwd account required /usr/lib/security/pam_prohibit passwd session required ... (13 Replies)
Discussion started by: pjeedu2247
13 Replies

6. UNIX for Dummies Questions & Answers

Quick UNIX command to display specific lines in the middle of a file from/to specific word

This could be a really dummy question. I have a log text file. What unix command to extract line from specific string to another specific string. Is it something similar to?: more +/"string" file_name Thanks (4 Replies)
Discussion started by: aku
4 Replies

7. Shell Programming and Scripting

How to print multiple specific column after a specific word?

Hello.... Pls help me (and sorry my english) :) So I have a file (test.txt) with 1 long line.... for example: isgc jsfh udgf osff 8462 error iwzr 653 idchisfb isfbisfb sihfjfeb isfhsi gcz eifh How to print after the "error" word the 2nd 4th 5th and 7th word?? output well be: 653 isfbisfb... (2 Replies)
Discussion started by: marvinandco
2 Replies

8. Shell Programming and Scripting

Replace a specific column with a specific value

Hi, I am looking to replacing value of a specific column of /etc/pam.d/system-auth file. My file looks like this password sufficient pam_unix.so md5 shadow nullok try_first_pass use_authtok expected result password sufficient pam_unix.so md5 shadow nullok try_first_pass use_authtok... (5 Replies)
Discussion started by: Litu1988
5 Replies

9. Shell Programming and Scripting

Overwrite specific column in xml file with the specific column from adjacent line

I have an xml file dumped from rrd file, that I want to "patch" so the xml file doesn't contain any blank hole in the resulting graph of the rrd file. Here is the file. <!-- 2015-10-12 14:00:00 WIB / 1444633200 --> <row><v> 4.0419731265e+07 </v><v> 4.5045912770e+06... (2 Replies)
Discussion started by: rk4k
2 Replies

10. Shell Programming and Scripting

Replace specific column delimiter

Hi All, I have a file with a pipe delimiter. I need to replace the delimiter with html tags. I managed to get all the delimiters replaced along with first and last but the requirement is that I need to change 7th delimiter with slight change. File1: ... (2 Replies)
Discussion started by: shash
2 Replies
AMOVERVIEW(8)						  System Administration Commands					     AMOVERVIEW(8)

NAME
amoverview - display file systems processed by Amanda over time SYNOPSIS
amoverview [--hostwidth width] [--diskwidth width] [--skipmissed] [--last] [--num0] [--togo0] [--verbose] [--config ] config DESCRIPTION
Amoverview displays a chart showing hosts and file systems processed by Amanda along with the backup level performed each day. See the amanda(8) man page for more details about Amanda. OPTIONS
--config config Use configuration config. --hostwidth width Set host field column width to width characters instead of 8. --diskwidth width Set disk field column width to width characters instead of 20. --skipmissed Compacts the output by only printing stats for the days Amanda actually ran. --last Outputs the last status of each disk at the start. Useful for long tapecycles and/or sparse reports. --num0 Outputs the number of level 0 dumps for each disk. --togo0 Outputs the number of runs until the last level 0 dump is overwritten. --verbose Amoverview can take a long while on large systems. This option reports intermediate steps while it is working. RESULTS
amoverview is a summary of the output of " amadmin <config> find ". When the last column of amadmin find contains anything other than "OK", amoverview translates this into "E" for that day. A number indicates the level of backup and it succeeded. An "E" indicates an error for that day. You get an "E" for all errors, like failed to connect, datatimeout, computer crashed, etc, but also for failing to write to tape. You can have an "E" followed by a number if a filesystem ran into end-of-tape once (gives an "E", and later that day, you flush it to a second tape (a number: the level, indicating success). If the flush failed too, you get a double "EE" for that day. You can also have a double code if you have two tapes in the changer and Amanda failed to write to tape the first time because it hit end of tape (resulting in "E0", for a full, "E1" for an incremental etc.) or twice with error ("EE"), and may a successful flush afterwards giving maybe "EE0". (Only the latest 2 characters are printed). EXAMPLE
This shows the /home file system on host2 was backed up at level 3 on the 8th, 9th and 10th of December, had a full backup on the 11th, a level 1 on the 12th and a level 2 on the 13th. # amoverview date 12 12 12 12 12 12 host disk 08 09 10 11 12 13 host1 / 0 1 1 1 1 1 host1 /var 0 1 1 1 1 1 host2 / 1 1 1 1 1 0 host2 /home 3 3 3 0 1 2 host2 /opt 1 1 1 1 1 1 host2 /var 1 1 0 1 1 1 SEE ALSO
amanda(8), amadmin(8) The Amanda Wiki: : http://wiki.zmanda.com/ AUTHOR
Stefan G. Weichinger <sgw@amanda.org> Amanda 3.3.1 02/21/2012 AMOVERVIEW(8)
All times are GMT -4. The time now is 09:59 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy