Wanted to replace string in an .xlsx file in multiple ZIP Files


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Wanted to replace string in an .xlsx file in multiple ZIP Files
# 1  
Old 09-03-2014
Wanted to replace string in an .xlsx file in multiple ZIP Files

Hi ,

I am having a ZIP file containing an .xlsx file . Now i wanted to replace "GJ" to blank in the .xlsx file .

I tried using the below code but not working , Please guide :
Code:
#!/bin/bash
log="/home/srikant/scripts/replacescriptFHO.log"
date > $log
echo "" >> $log
echo initiating for FHO >> $log
#dfolder="$(date +%d%m%Y --date='-1 day')"
dfolder="$(date +%d%m%Y)"


cd /fs/BHARTI_GUJARAT/TXN/FHO/
echo inside directory- `pwd` >> $log

newAddress=""
oldAddress="GJ"

for fname in file1.zip
do

  zipgrep -q $oldAddress $fname;  

echo hi 1 >> $log 
 
  if [ $? -eq 0 ]; then

echo hi 2 >> $log 

     filename="${fname%.*}" 

echo $filename >> $log

     unzip -qp $fname | sed -e 's#'$oldAddress'#'$newAddress'#g' FE_REPORT* 


     zip $filename.zip $filename
  fi
done

echo FHO done >> $log
echo ------------------------------------------------ >> $log


Last edited by Franklin52; 09-03-2014 at 10:13 AM.. Reason: Please use code tags
# 2  
Old 09-03-2014
Your script wont work because a "*.xlsx" file isn't a text file but a (MS Excel) formatted text file...as such it cant be worked on by Linux/Unix utilities like sed etc...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How can we Zip multiple files created on the same date into one single zip file.?

Hi all i am very new to shell scripting and need some help from you to learn 1)i have some log files that gets generated on daily basis example: i have abc_2017_01_30_1.log ,2017_01_30_2.log like wise so i want to zip this 4 logs which are created on same date into one zip folder. 2)Post zipping... (1 Reply)
Discussion started by: b.saipriyanka
1 Replies

2. UNIX for Beginners Questions & Answers

How can we Zip multiple files created on the same date into one single zip file.?

Hi all i am very new to shell scripting and need some help from you to learn 1)i have some log files that gets generated on daily basis example: i have abc_2017_01_30_1.log ,2017_01_30_2.log like wise so i want to zip this 4 logs which are created on same date into one zip folder. 2)Post zipping... (2 Replies)
Discussion started by: b.saipriyanka
2 Replies

3. Shell Programming and Scripting

Zip Multiple files to One .zip file in AIX system

Hi I have a requirement in unix shell where I need to zip multiple files on server to one single .zip file. I dont see zip command in AIX and gzip command not doing completely what I want. One I do .zip file, I should be able to unzip in my local Computer. Here is example what I want... (9 Replies)
Discussion started by: RAMA PULI
9 Replies

4. Shell Programming and Scripting

Script to find & replace a multiple lines string across multiple php files and subdirectories

Hey guys. I know pratically 0 about Linux, so could anyone please give me instructions on how to accomplish this ? The distro is RedHat 4.1.2 and i need to find and replace a multiple lines string in several php files across subdirectories. So lets say im at root/dir1/dir2/ , when i execute... (12 Replies)
Discussion started by: spfc_dmt
12 Replies

5. UNIX for Dummies Questions & Answers

replace string in multiple files

Hi, I'm new to Unix. My understanding of Unix and its command is very limited. I have about 1000 text files that have a word in it that I need to replace with a different word. e.g. a.txt has 1 line of txt: monday, tuesday, wednesday b.txt has 1 line of txt: monday, tuesday,... (5 Replies)
Discussion started by: millsy5
5 Replies

6. Shell Programming and Scripting

replace (sed?) a string in file with multiple lines (string) from variable

Can someone tell me how I can do this? e.g: a=$(echo -e wert trewt ertert ertert ertert erttert erterte rterter tertertert ert) How do i replace the STRING with $a? I try this: sed -i 's/STRING/'"$a"'/g' filename.ext but this don' t work (2 Replies)
Discussion started by: jforce
2 Replies

7. Shell Programming and Scripting

replace (sed?) a single line/string in file with multiple lines (string) from another file??

Can someone tell me how I can do this? e.g: Say file1.txt contains: today is monday the 22 of NOVEMBER 2010 and file2.txt contains: the 11th month of How do i replace the word NOVEMBER with (5 Replies)
Discussion started by: tuathan
5 Replies

8. Shell Programming and Scripting

String search and replace in multiple files.

Hello. I have five config files in /etc that I want to edit in one click for testing. I would like to make a script like this : #!/bin/bash # a_file="/etc/file_1" src_str="src_string_1" rpl_str="rpl_string_1" calling_sed_or_awk_or_whatelse $a_file search_for_all $src_str replace_with... (4 Replies)
Discussion started by: jcdole
4 Replies

9. AIX

ZIP multiple files and also specify size of zip file

I have to zip many pdf files and the size of zip file must not exceed 200 MB. When size is more than 200 MB then multiple zip files needs to be created. How we can achieve this in UNIX? I have tried ZIP utility but it takes a lot of time when we add individual pdfs by looping through a... (1 Reply)
Discussion started by: tom007
1 Replies

10. UNIX for Dummies Questions & Answers

Find and replace a string in multiple files

I used the following script cd pathname for y in `ls *`; do sed "s/ABCD/DCBA/g" $y > temp; mv temp $y; done and it worked fine for finding and replacing strings with names etc. in all files of the given path. I'm trying to replace a string which consists of path (location of file) ... (2 Replies)
Discussion started by: pharos467
2 Replies
Login or Register to Ask a Question