Help require to edit multiple files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help require to edit multiple files
# 1  
Old 12-11-2014
Help require to edit multiple files

I have 6 different pipe delimiter files. My loads failing due to missing company code.

File1: 31 st field is company code.

Code:
402660076310|2014-12-10 17:22:39|2280361|MRYKI|1||CA|92507|US||1|1|0|0|0||N|A1|ONT|1001891771660009250700402660076310|WM|0201|RALA |2014-12-12|5|2014-12-12|5||FRI - 12 DEC 10:30A||FK   |01|01|||||||||||||||||||||||||||||||||||

File2: Last filed is company code here.
Code:
840113359200|772172265209|1|N|Y|33161|US|101|10.22|100|N|N|N|N|N|0|7.9|N|barbara azcoy|1500 ne 131 st|Miami|FL|0|N|N||7862819178|N|N|N||world emblem|3449794|7.9|N|10.22|0|10.22|N|0|N|N|N|10.22|1|O||||||||RBLK|FK

File 3: 10th field is company code here.
Code:
840113401067|0|11.04|0|0||0||4482366|FK||US

I want to figure it out all null records and replace with "FK" in all files. Could you please help here ?
# 2  
Old 12-11-2014
Post what you've tried to solve this on your own...
# 3  
Old 12-11-2014
Try

Code:
awk -F'|'  '{ for (i=1;i<=NF;i++) if ($i=="") $i="FK"}1' OFS='|' infile

you can do all 6 in a loop

Code:
for file in file1,file2,file3,file4,file5,file6
done
awk -F'|'  '{ for (i=1;i<=NF;i++) if ($i=="") $i="FK"}1' OFS='|' $file > out-$file
done

This User Gave Thanks to senhia83 For This Post:
# 4  
Old 12-11-2014
How do we identify which field holds the company code? By field count? Your samples have 68, 55, and 12 fields, respectively.
# 5  
Old 12-11-2014
Quote:
Originally Posted by RudiC
How do we identify which field holds the company code? By field count? Your samples have 68, 55, and 12 fields, respectively.
I actually wanted to search "|FK|" in the file and take that position. Based on that position if any nulls are presented replace with "FK".

Now i found a way with above suggestion. I have kept file names and positions in one lookupfile and executing command something like as follows.

Code:
awk -F'|' 'NR>1 {if($6=="") $6="FK"}1' OFS='|' <file_name>

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using sed to edit multiple files

Created a shell script to invoke sed to edit multiple files, but am missing something. Here's the shell script: oracle:$ cat edit_scripts.sh #!/bin/sh #------------------------------------------------------------------------------ # edit_scripts.sh # # This script executes sed to make global... (4 Replies)
Discussion started by: edstevens
4 Replies

2. Shell Programming and Scripting

Edit and replace the multiple values in a file in one iteration

Hi All, I am preserving OLD and NEW values and want to replace the values in one go instead of using multiple sed and mv commands. Please help. echo "\nEnter the new qStart time '${CODE}' - (Hit Enter for No Change): \c" read NEW echo "\nEnter the new qStop time '${CODE}' - (Hit Enter for... (2 Replies)
Discussion started by: sdosanjh
2 Replies

3. Shell Programming and Scripting

Need Help to Edit multiple column of a file

Hello Team, I want to know if there is any one liner command , using which I can edit multiple column of a file. input file input.txt (comma separated), taran, 12.45, uttam, 23.40, babay karan, 12.45, raju, 11.40, rahulg I want to update, 2nd and 4th column, but want all those column... (8 Replies)
Discussion started by: Uttam Maji
8 Replies

4. Shell Programming and Scripting

Require single command to start script in multiple servers

I have 9 servers, on each server a script with common name is available. I send a token file to all server from 1 particular server. so when a daemon job checks that token file is available then it triggers the script.. I want to know is there any command or script which I will run/execute on... (16 Replies)
Discussion started by: mirwasim
16 Replies

5. UNIX for Advanced & Expert Users

awk - remove block of text, multiple actions for 'if', inline edit

I'm having a couple of issues. I'm trying to edit a nagios config and remove a host definition if a certain "host_name" is found. My thought is I would find host definition block containing the host_name I'm looking for and output the line numbers for the first and last lines. Using set, I will... (9 Replies)
Discussion started by: mglenney
9 Replies

6. Shell Programming and Scripting

Read and edit multiple files using a while loop

Hi all, I would like to simply read a file which lists a number of pathnames and files, then search and replace key strings using a few vi commands: :1,$s/search_str/replace_str/g<return> but I am not sure how to automate the <return> of these vis commands when I am putting this in a... (8 Replies)
Discussion started by: cyberfrog
8 Replies

7. Shell Programming and Scripting

How to edit file sections that cross multiple lines?

Hello, I'm wondering where I could go to learn how to edit file sections that cross multiple lines. I'm wanting to write scripts that will add Gnome menu entries for all users on a system for scripts I write, etc. I can search an replace simple examples with sed, but this seems more complex. ... (8 Replies)
Discussion started by: Narnie
8 Replies

8. Shell Programming and Scripting

Require script to create two files

Hi folks, I have a input.file with the following contents:- flor geor enta vpal domi pegl cars mted four rose annc gabi ward dalv elph beac (8 Replies)
Discussion started by: mithalr
8 Replies

9. AIX

Locking a file when using VI to prevent multiple-edit sessions by diff users

At the office, we often have to edit one file with VI. We are 4-6 workers doing it and sometimes can be done at the same time. We have found a problem and want to prevent it with a file lock. Is it possible and how ? problem : Worker-a starts edit VI session on File-A at 1PM Worker-b... (14 Replies)
Discussion started by: Browser_ice
14 Replies

10. UNIX for Dummies Questions & Answers

Edit Multiple Files in VI

Here's what I have... $ vi foo1 - open foo1 and work around for a while. I yank a few lines into a buffer and then :w to save. Next I :e foo2 to open foo2 and paste my buffer. I :w to save, but I would like to then be able to go directly back into foo1 where I was before I opened foo2. ... (4 Replies)
Discussion started by: djschmitt
4 Replies
Login or Register to Ask a Question