Gunzip and edit many files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Gunzip and edit many files
# 8  
Old 07-07-2017
If you could make 100% sure "setup..." and "DN" will always precede "<Target" in your files, a very simple awk code could be offered.

I can confirm the above.
setup and DN will always preceded '<Target'.

I responded how I did in the hopes that I might help someone else in the future.
I didn't realize how inefficient the code was.

Thanks for pointing that out.
# 9  
Old 07-07-2017
No problem. In fact, these fora appreciate people publishing their attempts so these can be analysed and discussed, so the learning curve for everyone becomes steeper.
Please become accustomed to provide decent context info of your problem.
It is always helpful to support a request with system info like OS and shell, related environment (variables, options), preferred tools, adequate (representative) sample input and desired output data and the logics connecting the two, and, if existent, system (error) messages verbatim, to avoid ambiguities and keep people from guessing.

Not knowing anything about your input file nor the desired output, just looking onto your code, I came up with
Code:
gunzip -c "${i}" | awk '
/<Setup/        {StartTime = "      " $0
                }
/DN/            {dn        = " " $0
                }
/<Target/       {$0 = $0 ORS dn ORS StartTime
                }
1
' > /tmp/"${FILE}"

Test and come back with results.
This User Gave Thanks to RudiC For This Post:
# 10  
Old 07-07-2017
Yup, below works great.
Thanks for the input and suggestions.

SmilieSmilieSmilieSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to decompress files using gunzip?

I have compressed files under directory '/root/data' and i need the uncompressed files in another directory '/root/uncom'. I running a shell script below shell script from directory '/root/' gunzip /root/data/*.gz -d /root/uncom But this is failing with : gunzip: /root/uncom is a directory... (2 Replies)
Discussion started by: hoyanet
2 Replies

2. Shell Programming and Scripting

Edit names of files in a directory

Hi all, I have a directory with multiple (thousnads) of files, which are named this way ABCDEF.wo.im-1 OKRAME.ire.roi IOJEAFO01.irt.gfg IMNYBL05.REG.gkf I would like to keep the part of the name (everything before the first dot in the filename). The desired output: ABCDEF... (3 Replies)
Discussion started by: Error404
3 Replies

3. Shell Programming and Scripting

How to decompress files using gunzip?

I have compressed files under directory '/root/data' and i need the uncompressed files in another directory '/root/uncom'. I running a shell script below shell script from directory '/root/' gunzip /root/data/*.gz -d /root/uncom But this is failing with gunzip: /root/uncom is a directory... (2 Replies)
Discussion started by: vel4ever
2 Replies

4. UNIX for Dummies Questions & Answers

Edit files with cat

Hi, sometimes one wants to edit files while still seeing output of earlier commands in terminal. I've found out that cat test && cat - >> test does the trick for displaying file content and adding lines but I believe I saw a much cooler command that was also able to erase lines from files. I cannot... (6 Replies)
Discussion started by: scarleo
6 Replies

5. Shell Programming and Scripting

Gunzip files

Hi ALL, Am working with the gunzip command to zip all the old files having 10 days am using the command find . -name '*.log' -type f -mtime +10 -exec gunzip {} \; am facing two issues 1.)it displays the files which are all older than a year 2.)when am trying to gunzip all the... (2 Replies)
Discussion started by: thelakbe
2 Replies

6. Shell Programming and Scripting

Gunzip files

Hello Everyone, I have a few files in a directory such as : abc.xyz.txt1.gz abc.xyz.txt2.gz .... .... ... ... abd.xyz.txt100.gz And I want uncompressed files such as: abc.xyz.txt1 abc.xyz.txt2 .... ... ..... .... (1 Reply)
Discussion started by: ad23
1 Replies

7. UNIX for Dummies Questions & Answers

edit _config files

Hi, I am trying to edit sshd_config file through the vi editor. logged on as a root. when I try to write the file I get: Read-only file, not written; use ! to override when i type :w!, I get: Error: etc/ssh/sshd_config Permission denied. I want to change: #PermitRootLogin no to yes freeBDS... (6 Replies)
Discussion started by: emosms
6 Replies

8. Gentoo

how to edit linux system files?

i had heard that linux is open source.....which meant that i could edit it. so how do i start out? i've already downloaded it. the name's "puppy linux".....someone please reply quick!!! and by the way, may i know what shell scripting is? (15 Replies)
Discussion started by: Dragster93
15 Replies

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

10. UNIX for Dummies Questions & Answers

how to edit large files using vi

How to edit large file using vi where you can't increase /usr/var/tmp anymore? (3 Replies)
Discussion started by: nazri
3 Replies
Login or Register to Ask a Question