Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I had 2 text files and same contain

Status
Not open for further replies.

ady2012

MIS
Jun 6, 2010
108
US
I had 2 text files and same contains. One text file created by vi and another text file created by shell script.
#!/bin/bash

read -p "Name: " name
read -p "Address: " address
read -p "City: " city
echo -e "Name: " $name"\nAddress: "$address"\nCity: "$city >>test1.txt

I also created one text file test.txt using vi below here:
Name: John
Address: elm street
City: New York

I put a same input in my shell script.
When I compared both text files using diff -d test.txt test1.txt. I got strange characters in text file using shell script. You can see my screen shot below here :



 
I can't see your screen shot attached, so I'm just going on your code. Other than a bunch of unnecessary quotes in the string being echoed, it looks OK to me.

Code:
#!/bin/bash

read -p "Name: " name
read -p "Address: " address
read -p "City: " city
echo -e "Name: $name\nAddress: $address\nCity: $city" > test1.txt

Both text files are identical on my system.

I'm using Red Hat 6 and BASH 3.2.25.

 
Sorry, My example text file was too short. My actual text file created by vi/nano below here :

dn: uid=ady2k,ou=users,dc=sl7,dc=org
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: shadowAccount
cn: ady2k
sn: Linux
userPassword: secret
loginShell: /bin/bash
uidNumber: 1000
gidNumber: 1000
homeDirectory: /home/ady2k
dn: cn=ady2k,ou=groups,dc=sl7,dc=org
objectClass: posixGroup
cn: ady2k
gidNumber: 1000
memberUid: ady2k

I want to use shell script generated same text file.
And I need to input usename, password, ou people, ou group, cn, uidnumber,gidnumber using shell script.
I also want to adduser after I want to rename a text filename match with username.
 
 http://files.engineering.com/getfile.aspx?folder=8e1f167f-026a-4832-8d78-64a0e192d960&file=shell_script_test_file.png
Well, from your '[tt]diff[/tt]' output, your files are identical except for two blank lines that are in one, but not the other. You should be able to see them better if you do side-by-side output. Try this command for your '[tt]diff[/tt]'...

Code:
diff -y test.txt test1.txt

Or, do a '[tt]diff[/tt]' that ignores blank lines...

Code:
diff -B test.txt test1.txt

If you decide that blank lines matter, then it should be easy to find where your extra blank lines are being inserted.

 
I had uploaded my screen shot. My problem wasnt blank but strange characters in text file generated by shell script. How to delete it?
 
U can try it and compare it using diff. U created text file using vi/nano and created anothet text file using shell script. And u can see the result.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top