Visit The New, Modern Unix Linux Community

UNIX file handling issue

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting UNIX file handling issue
# 1  
UNIX file handling issue

I have a huge file semicolon( ; ) separated records are Pipe(|) delimited.


I need to replace the 50th field(semicolon separated) of each record with 9006. The 50th field can have no value e.g. ;;

Can someone help me with the appropriate command.

Last edited by Scrutinizer; 11-13-2012 at 09:42 PM.. Reason: code tags
# 2  
I haven't tried it but you can try it :
awk -F";" '{$50=9006}1' RS="|" OFS=";" ORS="|" yourfile

awk -F";" '{for(i=1;i<=NF;i++){if(!(i%50)){$i=9006}}}1' OFS=";" RS=ORS="|" yourfile

Last edited by ctsgnb; 11-13-2012 at 08:56 PM..
# 3  
Thanks for the code. But I am getting error on UNIX.

fwtwc@meraqapp01:/openet/u0002/test_files$ awk -F";" '{for(i=1;i<=NF;i++){if(!(i%50)){$i=9006}}}1' OFS=";" RS=ORS="|" newfile.dat
awk: syntax error near line 1
awk: bailing out near line 1

what can be a possible reason. Even tried running
#!/bin/awk -f

before the command

---------- Post updated at 01:26 AM ---------- Previous update was at 01:00 AM ----------

nawk worked for me instead of awk.

But another issue came in some records are of less than 50 in lengths also if the record is not present at all like "||" then the data is getting populated as

|1000;2012-08-20 00:22:55;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;9006|

I dont want any data inside two Pipe separated records. Or if the number of ';' separated fields is less than 50

Last edited by Franklin52; 11-15-2012 at 04:02 AM.. Reason: Please use code tags for data and code samples
# 4  
Try to extend ctsgnb's code like
awk -F";" 'NF>=50{$50=9006}1' RS="|" OFS=";" ORS="|" yourfile

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #618
Difficulty: Medium
Python is strongly object-oriented in the sense that everything is an object including numbers, strings and even functions.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Issue handling single quoted argument in shell script.

Below is my script that works fine and prints the desired output: #!/bin/ksh echo "$1" | while IFS= read -r dirpath do echo "DIRR_PATH:$dirpath" install_dir=$install_dir" "$dirpath done echo "Desired Output:$install_dir" Output: ./ (10 Replies)
Discussion started by: mohtashims
10 Replies

2. UNIX for Dummies Questions & Answers

File handling issue

Hi All, I am running into an issue. I have a very big file. Wants to split it in smaller chunks. This file has multiple header/ trailers. Also, between each header/trailer there are records. Number of records in each header trailer combination can vary. Also, headers can start with... (3 Replies)
Discussion started by: Gurkamal83
3 Replies

3. Shell Programming and Scripting

ISSUE in handling multiple same name files :-(

Dear all, My work is completely stuck cos of the following issue. Please find it here and kindly help me. Task is following: I have set of files with such pattern 1t-rw-rw-r-- 1 emily emily 119 Jun 11 10:45 vgtree_5_1_pfs.root 3t-rw-rw-r-- 1 emily emily 145 Jun 11 10:46 vgtree_5_3_pfs.root... (4 Replies)
Discussion started by: emily
4 Replies

4. UNIX for Dummies Questions & Answers

Large file data handling issue

I have a single record large file, semicolon ';' and pipe '|' separated. I am doing a vi on the file. It is throwing an error "File to long" I need to actually remove the last | symbol from this file. sed -e 's/\|*$//' filename is working fine for small files. But not working on this big... (13 Replies)
Discussion started by: Gurkamal83
13 Replies

5. Shell Programming and Scripting

Issue with Error handling,not able to continue the script further

Hi, I am trying to write a script to cleanup files in a log directory .. cd log find Datk** -mtime +7 -exec rm -f {} \; 2> /dev/null Have used the above to clean up files in log directory more then 7 days older. The file can be something like ( auto-generate by some processes and... (2 Replies)
Discussion started by: nss280
2 Replies

6. Shell Programming and Scripting

UNIX File handling -Issue in reading a file

I have been doing automation of daily check activity for a server, i have been using sqls to retrive the data and while loop for reading the data from the file for several activities. BUT i got a show stopper the below one.. where the data is getting store in $temp_file, but not being read by while... (1 Reply)
Discussion started by: KuldeepSinghTCS
1 Replies

7. UNIX for Dummies Questions & Answers

File Handling in UNIX

Hi all, I have a requirement here where I am dealing with a dynamic file. Each record in the file can contain anywhere between 1(min) to 42(max) Reject codes. For example I may have one record in the file having 3 reject codes and another record having 5 reject codes. The reject codes will be... (2 Replies)
Discussion started by: sujainarayan
2 Replies

8. Shell Programming and Scripting

Performance issue in UNIX while generating .dat file from large text file

Hello Gurus, We are facing some performance issue in UNIX. If someone had faced such kind of issue in past please provide your suggestions on this . Problem Definition: /Few of load processes of our Finance Application are facing issue in UNIX when they uses a shell script having below... (19 Replies)
Discussion started by: KRAMA
19 Replies

9. Shell Programming and Scripting

File handling, getopts command in unix

I need to create a shell script having the menu with few options such as 1. Listing 2. Change permissions 3. Modify Contents 4. Delete Files 5. Exit 1. For 1. Listing: Display a special listing of files showing their date of modification and access time (side by side) along with their... (2 Replies)
Discussion started by: bab123
2 Replies

10. UNIX for Dummies Questions & Answers

File handling in UNIX

Hi All, I want to read a file in UNIX line by line. Can u suggest me any command for this? (4 Replies)
Discussion started by: VENC22
4 Replies

Featured Tech Videos