LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-05-2009, 11:13 AM   #1
saawan
LQ Newbie
 
Registered: May 2009
Posts: 5

Rep: Reputation: 0
converting a py script to bash


Need help in converting this script to a bash script. here is command

script.sh first_file second_file

here is the python script.

this script is written to dump first_file until it find a specific line then dumps sceond_file until it ends then continues dumping the first file.


f = open(sys.argv[1], "r")
while True:
line = f.readline()
if not line:
break

print line.replace('\n', '')
if (line.find('<PF_B64EN encoding') != -1):
license_file = open(sys.argv[2], "r")
while True:
line1 = license_file.readline()
if not line1:
break
print ("\tlist.append(\"" + line1.replace('\n', '') + "\")")
 
Old 05-05-2009, 12:02 PM   #2
tenko20xx
LQ Newbie
 
Registered: Jan 2009
Distribution: Linux Mint
Posts: 7

Rep: Reputation: 0
Here you go, hope this works for you:

Code:
#!/bin/bash

if [ $# != 2 ]; then
        echo "Usage: script.sh [file1] [file2]"
        exit
fi

if [ ! -f $1 ]; then
        echo "Error: Could not find file '$1'"
        exit
fi

if [ ! -f $2 ]; then
        echo "Error: Could not find file '$2'"
        exit
fi

IFS=$'\n'
for i in $(cat $1); do
        echo $i
        if [[ $i == *"<PF_B64EN encoding"* ]]; then
                for j in $(cat $2); do
                        echo $j
                done
        fi
done
 
Old 05-06-2009, 11:56 AM   #3
saawan
LQ Newbie
 
Registered: May 2009
Posts: 5

Original Poster
Rep: Reputation: 0
thanks - it worked.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting extended ascii (ë,ô) in bash script Hko Programming 4 12-29-2012 03:42 AM
converting string in integer in bash script dziadgba Linux - Newbie 5 08-31-2009 05:59 PM
BASH script for converting ogg to mp3. hacker supreme Programming 4 06-30-2009 02:39 PM
converting bash script to csh DJOtaku Programming 8 02-13-2006 05:35 AM
bash script for converting ps to pdf juergenkemeter Linux - General 3 10-10-2005 04:35 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:24 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration