08-30-2011
How can I add a newline In a text file using Shell Script
Good day ...
Well i do have this project in school, in our Principles Of Operating System Class
We are using Cygwin....
And our project goes like this...
Create a dictionary using cygwin. Display the following menu at the start of
execution
1-add a word in the dictionary # specify the meaning
2-search a word # if word exists, show the meaning of the word
2-delete a word
4-delete all words in the dictionary
#NOTE: The program should ask the user if he wishes to continue or not.
And here is my Code....
ans=yes
while [ $ans = yes ]
do
echo 1-Add a word in the dictionary
echo 2-Search a word in the dictionary
echo 3-Delete a word in the dictionary
echo 4-Delete all words in the dictionary
echo -n "Choose which to execute: "
read ENTRY
case $ENTRY in
1)
echo -n "Enter a word: "
read word
echo $word " " | cat >> word.txt
echo -n "Enter the meaning: "
read meaning
echo $meaning | cat >> word.txt
;;
2)
SUCCESS=0
echo -n "Enter the word to search: "
read word
grep -q "$word" "word.txt"
if [ $? -eq $SUCCESS ]
then
awk "/$word/" word.txt
else
echo Word not found!
fi
;;
3)
#I still don't know what code to delete a word from the textfile
#If you can supply a good code to delete a word, that would be a big help
;;
4)
echo | cat > word.txt | echo Successfully Deleted!
;;
echo -n "Do you want to continue?yes or no: "
read ans
done
In the case 1 , I wanted that everytime I save a word & meaning to a notepad it
would appear like this in the notepad
#example
Clandestine means Secret
Loquacious means Talkative
but in my code, it appears like this in the notepad
#example
Clandestine means Secret Loquacious means Talkative
Does anyone know what is the code for my desired output in the notepad in case 1?
Can anybody help me with my code , especially in case 1 and case 3?
Your immediate response regarding this matter is so much appreciated
Thank you so much in advance ^_^ God bless ....
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi Everybody,
I need some help on formatting the files coming into unix box on the fly.
I get a file some thing like this in a single line.
ISA^M00^M ^M00^M ^M14^M006929681900 ^M01^M095449419 ... (5 Replies)
Discussion started by: ntekupal
5 Replies
2. Shell Programming and Scripting
Hi All,
I am tring to insert a newline with "/" in a text file whenever there is the text "end;"
right now I have inside file:
.
.
end;
I want to have:
.
.
end;
/
I tried doing the following within the file
:g/^end;/s//end; \/ / (4 Replies)
Discussion started by: jxh461
4 Replies
3. Shell Programming and Scripting
Hi all,
I am beginner in UNIX...I want to use unix shell script to create text.file...I know how to use using by command...can anybody tell me for the script?
Thanks
i changed the threads title from "tex file" to "text file", because "tex" would probably be misunderstood as reference to... (4 Replies)
Discussion started by: mastercar
4 Replies
4. Shell Programming and Scripting
Hello,
Need help substituting a particular word in a file having a single line but no newline character at the end.
I was trying to use sed but it doesn't work probably because there is no newline char at the end of the line.
$ cat hlq_detail
/outputs/alvan23/PDFs/bills
$ cat... (5 Replies)
Discussion started by: Shan_u2005
5 Replies
5. Shell Programming and Scripting
Hi All,
Just need small help in resolving the special new line character in generated output file.
In one of my shell script I am using following lines to get the spool file (i.e. sfile.txt) and
AAA_XXXX_p111_n222.txt
AAA_YYYY_p111_n222.txt
Here assuming
v_pnum="p111"
v_nid="n222"
... (1 Reply)
Discussion started by: shekharjchandra
1 Replies
6. Shell Programming and Scripting
Hi all,
I'm not exactly a shell script guru, so this is probably a very silly question and I'm not seeing the point, but you know, sometimes it happens...
I have this script which adds entries to local arp cache using it to find the corresponding IP address.
# export MAC=00:25:90:34:3d:f2... (16 Replies)
Discussion started by: micantox
16 Replies
7. Shell Programming and Scripting
Good day ...
Well i do have this project in school, in our Principles Of Operating System Class
We are using Cygwin....
And our project goes like this...
Create a dictionary using cygwin. Display the following menu at the start of execution
1-add a word in the dictionary # specify the... (1 Reply)
Discussion started by: kpopfreakghecky
1 Replies
8. Shell Programming and Scripting
Greetings!
Can we automate the process of removing a newline char from selected rows in a fixed width file using a shell?
Input is like
abcd1234
xyzd1234
abcd
a1b2c3d4
abcd1234
xyzd1234
xx
abcd1234
Expected output -
abcd1234xyzd1234
abcda1b2c3d4abcd1234xyzd1234
xxabcd1234
... (3 Replies)
Discussion started by: mailme0205
3 Replies
9. Shell Programming and Scripting
Hi All,
I have following piece of code in UNIX C Shell script and I want to add one more command which can add newline at the end of file only if there is no newline character exists.
foreach file (`ls $dd_PLAYCARD_EDI_IN`)
if ( -f $dd_PLAYCARD_EDI_IN/${file} ) then
cat -n... (4 Replies)
Discussion started by: jnrohit2k
4 Replies
10. UNIX for Dummies Questions & Answers
sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies
LEARN ABOUT SUSE
dpbindic
DPBINDIC(1) General Commands Manual DPBINDIC(1)
NAME
dpbindic - Convert a binary-form dictionary into a text-form dictionary
SYNOPSYS
dpbindic [ -xiu [ frequency ] ] binary-file [ text-file ]
DESCRIPTION
dpbindic outputs the file information of the binary-form dictionary file specified in binary-file . At this time, the word information of
the dictionary can be output in text form to the standard output. To do so, use test-file to specify the text-form dictionary used as the
source of binary-form dictionary file. If this specification is omitted, the text dictionary file information in the binary dictionary
file will be output. The standard grammar file name is /usr/local/canna/lib/dic/hyoujun.gram. It will be used if the grammar file name
specification is omitted. The output format of word information data is specified using an option.
OPTIONS
-x Outputs the data without using omission symbol @, which is used when the initial word represents the reading.
-i Replaces the reading and word for output.
-u Outputs the candidates used in conversion. Outputs all candidates having frequency or more. If frequency is omitted, all candi-
dates having frequency 1 will be output.
EXAMPLES
(1) If the text-form dictionary file name is omitted:
%dibindic iroha.cbd
(Text dictionary file name = Directory size + Word size, packed)
iroha.swd = 2985 + 5306 pak a4
iroha.mwd = 36276 + 113139 pak a4
(2) If the text-form dictionary file name iroha.mwd is specified:
%dpbindic iroha.cbd iroha.mwd
(Text dictionary file name = Directory size + Word size, packed)
iroha.mwd = 36276 + 113139 pak a4
SEE ALSO
mkbindic(1), dicar(1)
DPBINDIC(1)