Register
It is currently Thu Oct 23, 2014 12:41 am

Bash Scipt Problem


All times are UTC - 6 hours


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 PostPosted: Mon Aug 30, 2010 8:39 am   

Joined: Mon Aug 30, 2010 8:33 am
Posts: 1
Hi,

I try to create a little bash scipt. This Script must read each character from a text file. If the character is a LineFeed (0x0a) then I would change it to CRLF. My Problem is that I canĀ“t strore a result from a command in a variable "test".

Code:
count=1
while read -n1 char
do

#echo $char
test=$($char | xxd -ps | sed 's/ //g)
echo $test

#if [ $test = "0a" ]; then
#   echo true
#else
#   echo false
#fi

(( count++ ))

done < /Users/christianseidl/Desktop/BashCode/137.emlx


Thank You


Top
 Profile  
 PostPosted: Mon Aug 30, 2010 3:25 pm   
Site Admin

Joined: Tue May 17, 2005 7:31 pm
Posts: 251
Location: Georgia
i see one error right off the bat... seems you aren't populating the variable "test" correctly
Code:
test=$($char | xxd -ps | sed 's/ //g)

in that example... nothing is starting the data flow for the pipes to work...
you are also missing the closing ' for the sed command...

you can try
Code:
test=$(echo $char | xxd -ps | sed 's/ //g')

to get it started... but I don't know what xxd is... so you are on your own from there :)


Top
 Profile  
 PostPosted: Mon Aug 30, 2010 5:18 pm   
User avatar

Joined: Tue Apr 27, 2010 2:28 pm
Posts: 172
Location: Czech Republic
Something like
Code:
sed 's/\r/\r\n/g'
?


Top
 Profile  
 PostPosted: Tue Aug 31, 2010 8:13 am   
Site Admin

Joined: Tue May 17, 2005 7:31 pm
Posts: 251
Location: Georgia
Depends on what you are looking for on what your sed line would be....

Here's my favorite page for sed oneliners... http://sed.sourceforge.net/sed1line.txt


And here's a snip from that page:
sed.sourceforge.net wrote:
TEXT CONVERSION AND SUBSTITUTION:

# IN UNIX ENVIRONMENT: convert DOS newlines (CR/LF) to Unix format.
sed 's/.$//' # assumes that all lines end with CR/LF
sed 's/^M$//' # in bash/tcsh, press Ctrl-V then Ctrl-M
sed 's/\x0D$//' # works on ssed, gsed 3.02.80 or higher

# IN UNIX ENVIRONMENT: convert Unix newlines (LF) to DOS format.
sed "s/$/`echo -e \\\r`/" # command line under ksh
sed 's/$'"/`echo \\\r`/" # command line under bash
sed "s/$/`echo \\\r`/" # command line under zsh
sed 's/$/\r/' # gsed 3.02.80 or higher

# IN DOS ENVIRONMENT: convert Unix newlines (LF) to DOS format.
sed "s/$//" # method 1
sed -n p # method 2

# IN DOS ENVIRONMENT: convert DOS newlines (CR/LF) to Unix format.
# Can only be done with UnxUtils sed, version 4.0.7 or higher. The
# UnxUtils version can be identified by the custom "--text" switch
# which appears when you use the "--help" switch. Otherwise, changing
# DOS newlines to Unix newlines cannot be done with sed in a DOS
# environment. Use "tr" instead.
sed "s/\r//" infile >outfile # UnxUtils sed v4.0.7 or higher
tr -d \r <infile >outfile # GNU tr version 1.22 or higher


Hope that helps...


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP