02-01-2009
csv file to array, match field1, replace in flat file field1 to field2
Hello, i am bit stuck with making script for automatic procedure.
Case:
Two files. One is flat file, other is csv file.
csv file has two column/fields with comma delimited data.
Here is what i need (explained way)
CSV file:
field1 | field2
"hello","byebye"
"hello2","byebye2"
"hello3","byebye3"
Flat file has matching data:
"hello"
"hello2"
"hello3"
If found:
"hello"
"hello2"
"hello3"
..in flat file, then it must be replaced from csv file with FIELD2 according
to search match.
But i have to search "hello" from csv file field1 data with flat file together and if found match in
flat file, it must be replaced from csv file with field2 data.
I know i could split csv file to two files, one containing field1 data and
second file field2 data but that would be not so dynamic way.
Though then i could easily use loop with cat + sed
Idea is to make nagios mass updating hosts naming changes in config.
So im wondering could i do it with awk or sed more universal way?
Any examples would be great help.
Thanks in advance..
Frankie
Last edited by frankie_konin; 02-01-2009 at 06:21 PM..
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi ,
I need to remove the 5th character of column1 and print the rest.
Can anybody give some advice?
Input:
0001c xx
0001r gg jj
0002y vv
0002p kk
0003q gg ll
0003v tt
0003t gg pp kk
Output:
0001 xx
0001 gg jj (9 Replies)
Discussion started by: Raynon
9 Replies
2. Shell Programming and Scripting
Hi ,
I have a file with contents as below:
Contract Cancellation Report UARCNCL
LOS CODE DATE REAS TYPE AMOUNT AMOUNT LETTER BY
========= ======= ==== ==== ==== ========= ==== ====
8174739 7641509 1S NONE CRCD 30-JUN-2008 NPAR N .00 .00 CCAN
8678696 8091709 1S NONE DDEB 30-JUN-2008... (14 Replies)
Discussion started by: rkumudha
14 Replies
3. Shell Programming and Scripting
Hi Guy's can someone help me in converting the following
I have a flat text file which has several thousand lines which I need to convert to a csv it's got a consistent format but basically want every time it hit's txt to create a new line with the subsequent lines comma delimited for example
... (6 Replies)
Discussion started by: p1_ben
6 Replies
4. Programming
Need help - hopefully I explain it correctly
I have a table in mysql database with multiple fields.
2 of the fields are called id and id_link
id id_link
93 http://test_server/testpage.cgi?93
95
96
97
98
I need to find the correct sql to update all of the id_link... (2 Replies)
Discussion started by: frustrated1
2 Replies
5. Shell Programming and Scripting
hi
i have written a script for reading a csv file and creating a flat file, suggest if this script can be optimized
#----------------
FILENAME="$1"
SCRIPT=$(basename $0)
#-----------------------------------------//
function usage
{
echo "\nUSAGE: $THIS_SCRIPT file_to_process\n"... (3 Replies)
Discussion started by: mprakasheee
3 Replies
6. Shell Programming and Scripting
Hi Friends,
I'm a great fan of this forum... it has helped me tone my skills in shell scripting. I have a challenge here, which I'm sure you guys would help me in achieving...
File A has a list of job ids and I need to compare this with the File B (*.log) and File C (extend *.log) and copy... (6 Replies)
Discussion started by: asnandhakumar
6 Replies
7. Shell Programming and Scripting
Good morning everyone and hello unix.com!
I'm trying to solve a problem and was unable to find a solution after a forum research. So hopefully you can help me get this solved.
I have these two csv files:
file1.csv
ID,REFERENCE,STATUS
1,2,0
2,4,1
3,1,0
file2.csv... (2 Replies)
Discussion started by: RKos
2 Replies
8. Shell Programming and Scripting
Hi, I am newbie in shell script.
I need your help to solve my problem.
Firstly, I have 2 files of csv and i want to compare of the contents then the output will be written in a new csv file.
File1:
SourceFile,DateTimeOriginal
/home/intannf/foto/IMG_0713.JPG,2015:02:17 11:14:07... (8 Replies)
Discussion started by: refrain
8 Replies
9. Shell Programming and Scripting
I am trying to create a cronjob that will run on startup that will look at a list.txt file to see if there is a later version of a database using database.txt as the source. The matching lines are written to output.
$1 in database.txt will be in list.txt as a partial match. $2 of database.txt... (2 Replies)
Discussion started by: cmccabe
2 Replies
10. Shell Programming and Scripting
Hi All,
I have a csv file which is comma seperated. I need to convert to flat file with preferred column length
country,id
Australia,1234
Africa,12399999
Expected output
country id
Australia 1234
Africa 12399999
the flat file should predefined length on respective... (8 Replies)
Discussion started by: rohit_shinez
8 Replies
LEARN ABOUT DEBIAN
csv2mipe
CSV2MIPE(1) User Contributed Perl Documentation CSV2MIPE(1)
NAME
csv2mipe.pl - Generates MIPE file based on 3 tab-delimited files
based on MIPE version v1.1
arguments: * tab-delimited file with PCR-level data
* tab-delimited file with SNP-level data
* tab-delimited file with assay-level data
Columns in file with PCR-level data:
pcr_id
pcr_modified (might be multiple, divided by semi-colon ";")
pcr_project (might be multiple, divided by semi-colon ";")
pcr_researcher (might be multiple, divided by semi-colon ";")
pcr_species
source_type
source_id
design_seq
primer1_oligo
primer1_seq
primer1_tm
primer2_oligo
primer2_seq
primer2_tm
design_remark (might be multiple, divided by semi-colon ";")
use_seq
use_revcomp
use_remark (might be multiple, divided by semi-colon ";")
pcr_remark (might be multiple, divided by semi-colon ";")
Columns in file with SNP-level data:
pcr_id
snp_id
snp_pos
snp_amb
snp_remark (might be multiple, divided by semi-colon ";")
Columns in file with assay-level data:
pcr_id
snp_id
assay_id
assay_type
assay_enzyme
assay_oligo
assay_specific
assay_tail
assay_strand
assay_remark (might be multiple, divided by semi-colon ";")
SYNOPSIS
csv2mipe.pl <pcr_file.csv> <snp_file.csv> <assay_file.csv>
ADDITIONAL INFO
See http://mipe.sourceforge.net
AUTHOR
Jan Aerts (jan.aerts@bbsrc.ac.uk)
perl v5.14.2 2005-07-20 CSV2MIPE(1)