Editing big file in UNIX


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Editing big file in UNIX
# 1  
Old 08-12-2014
Display Editing big file in UNIX

Hi Guys,
I have a hugefile. I have requirement to change Indicator from "T" to "P" or from "P" to "T" which comes in header itself. I could not open either in any of editors or in UNIX command line using vi as file size > 3GB

Please suggest a solution as how to achieve it through script or any single line commands.

Note: This indicator comes in ISA 15 segment.

Example:

Code:
ISA*00* *00* *08*92 *08*123*030627*1304*U*00*00*0*P*>~


I have change it to

Code:
ISA*00* *00* *08*92 *08*123*030627*1304*U*00*00*0*T*>~


Last edited by Corona688; 08-12-2014 at 03:01 PM..
# 2  
Old 08-12-2014
Please use code tags for code, [code]stuff[/code]. Or select the text you wish to wrap and hit the Image button.

Do I understand you to mean that you wish to change exactly one character in the very first line of this file?

Editing the original file is fraught with danger. One mistake and you've trashed 3GB of data. Do you have backups?
# 3  
Old 08-13-2014
Yes you understanding is correct. I just need to change one character in file which comes in ISA 15 segment. Segment delimter is "*".
I have back up of file so no worries
# 4  
Old 08-13-2014
Are the field sizes for the 1st 15 ISA segments all fixed-width (or more importantly, is the "P" you want to change always the 51st character on the line)?

What is the maximum length of the 1st line in this file (in bytes)?

Will you tell your script you want that segment to be "T" or "P"? Or, is your script supposed to find the character that is there and reverse it?

Last edited by Don Cragun; 08-13-2014 at 10:07 AM.. Reason: Add another question.
# 5  
Old 08-13-2014
The total length of first file is 106 bytes. This indicator comes in 103 position. The script can be interactive such as

Enter the folder:
Enter the file name:
Change from T to P: Y/N
Change from P to T: Y/N
# 6  
Old 08-13-2014
Quote:
Originally Posted by Abdulhameed M
The total length of first file is 106 bytes.
??? You told us they are 2 GIGAbytes, far too large to edit.

Quote:
This indicator comes in 103 position.
??? You show it in position 51!

I'm not going to make wild guesses about the true nature of your data. Edit this script as you see fit. It works for the line you posted.

Code:
# Read first line of file
IFS="" read -r LINE < hugefile

# Check the 51st character
case "${LINE:50:1}" in
P)
        Z="T";
        ;;
T)
        Z="P";
        ;;
*)
        echo "$LINE has nothing valid to change"
        exit 1
        ;;
esac

printf "Change ${LINE:50:1} to ${Z} [Y/N] "

# Try read -n 1 REPLY, if you don't want it to wait for ENTER key.
read REPLY

[ "$REPLY" = "Y" ] || exit


printf "%s" "${LINE:0:50}${Z}${LINE:51}" | dd of=hugefile conv=notrunc


Last edited by Corona688; 08-13-2014 at 11:11 AM..
# 7  
Old 08-13-2014
Thanks for your quick reply.. I will test and get back..
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. HP-UX

Editing a UNIX file in Hexadecimal format

Hi, I am a newbie to the UNIX world. I am asked to edit the file in hexadecimal format and save it. Later I should be able to print the file in char mode. please anyone tell me how to do that mostly using VI editor. (1 Reply)
Discussion started by: vkudire
1 Replies

2. UNIX for Advanced & Expert Users

best method to compare 2 big files in unix

Hi , I have a requirement to compare 2 files which can contain 40 million or more records and more than 20 fields to compare . Currently I am using awk scripting , and since awk has a memory issue, I am not able to process file more than 10 million records. Any suggestions or pointers to... (7 Replies)
Discussion started by: rashmisb
7 Replies

3. UNIX for Dummies Questions & Answers

How big is too big a config.log file?

I have a 5000 line config.log file with several "maybe" errors. Any reccomendations on finding solvable problems? (2 Replies)
Discussion started by: NeedLotsofHelp
2 Replies

4. Shell Programming and Scripting

Editing Binary Files in Unix

Hi, Is there a way to edit BINARY files in Unix. Or even are there any commands (shellscript/perl) through which I can replace all the occurences of a string inside a BINARY file with another string ?? (1 Reply)
Discussion started by: cool.aquarian
1 Replies

5. UNIX for Dummies Questions & Answers

problem editing big file in vi

I have a big file, which vi opens it with message not sufficient space with file system. I am not adding any data in the file but changing some values within. To make these changes effective, it asks for forced write (w!), even after doing this, I see this particular record, change is not... (4 Replies)
Discussion started by: videsh77
4 Replies

6. SCO

File Editing and Printing in Unix

Hi, Can some one provide me with, some good links containing help for file editing and printing in unix. Regards, Muhammad Tayyab Shereen Motor Co. Kuwait (1 Reply)
Discussion started by: tayyabq8
1 Replies

7. UNIX for Dummies Questions & Answers

How to view a big file(143M big)

1 . Thanks everyone who read the post first. 2 . I have a log file which size is 143M , I can not use vi open it .I can not use xedit open it too. How to view it ? If I want to view 200-300 ,how can I implement it 3 . Thanks (3 Replies)
Discussion started by: chenhao_no1
3 Replies

8. UNIX for Dummies Questions & Answers

editing unix files on NT

i currently am using a unix server and NT pc. i have downloaded a ziped file that should explode into 3 seperate unix based files, however when i unzip it using Alading Expander it displays only 1. This exploded version contains all 3 files ( you can scroll down when viewing the file and see the... (1 Reply)
Discussion started by: pixelmonkey
1 Replies
Login or Register to Ask a Question