[Solved] Reading the last word in a file from a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] Reading the last word in a file from a script
# 1  
Old 01-26-2012
[Solved] Reading the last word in a file from a script

Hello everybody,

My first time here and my english is not very good I hope you understand me.

I'm trying to read a file that contains two zip archive names.
Here my file content is:
package1.zip package2.zip

At the end of the line there is a \n character.

I read this file from a script shell with a while loop, the reading code is:
Code:
while read -r Package_App Package_Cat
do
echo "$Package_App"
echo "$Package_Cat-----"
done < $FIC_PARAM

The result does not correct because in Package_Cat variable I have the '\n' character too! So, later in my script I can't use the $Package_Cat for finding the archive .zip.

Anyone knows how Can I have only 'package2.zip' in my Package_Cat variable without the \n character?

Thanks so much!!!

Moderator's Comments:
Mod Comment Please use next time code tags for your code and data

Last edited by vbe; 01-26-2012 at 10:31 AM..
# 2  
Old 01-26-2012
The $FIC_PARAM file you read is of what origin? DOS?
If DOS (WIN...) then convert the files with dos2ux or dos2unix command before...
# 3  
Old 01-26-2012
Yesss!!! it was that!
Thank you so much vbe!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

UNIX script to check word count of each word in file

I am trying to figure out to find word count of each word from my file sample file hi how are you hi are you ok sample out put hi 1 how 1 are 1 you 1 hi 1 are 1 you 1 ok 1 wc -l filename is not helping , i think we will have to split the lines and count and then print and also... (4 Replies)
Discussion started by: mirwasim
4 Replies

2. Shell Programming and Scripting

[Solved] Need Help in reading Response file

Hi All, I have a requirement to read response file which looks like below Ex: NAME=SAM DOB=01/01/1980 ADDRESS= 7658 James Street NewYork 0000 Now, I need to take NAME, DOB, ADDRESS into variables I am fine taking NAME and DOB I need help on how can I... (6 Replies)
Discussion started by: mallak
6 Replies

3. UNIX for Dummies Questions & Answers

[Solved] Reading Array And Send An Email

I am trying to find an example for reading an array instead of reading a file and send out an email in ksh. Can you please help is that possible? Algorithm #!/bin/ksh i=0 set -A ARR if then let i=$ ARR="A does n't match with B" fi if then let i=$ ARR="P does n't match with Q"... (11 Replies)
Discussion started by: Ariean
11 Replies

4. Programming

[Solved] Problem with fork() while reading files

Good evening everyone. I have my finals and I'm facing a problem: I have a for cycle that is supposed to fork 2 children but somehow it forks only the first one. What am I doing wrong ? #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h>... (5 Replies)
Discussion started by: pfpietro
5 Replies

5. Shell Programming and Scripting

[Solved] Search for a word and print the next word

Hi, I am trying to search for a word and print the next word. For example: My text is "<TRANSFORMATION TYPE ="Lookup Procedure">" I am searching for "TYPE" and trying to print ="Lookup Procedure" I have written a code like following: echo $line | nawk... (4 Replies)
Discussion started by: sampoorna
4 Replies

6. Shell Programming and Scripting

Reading a word from a text file into shell script

Hi, I am new to shell programming.I need to write a script that would accept a word from each line fo an input text file.Can anyone help me with this?Exact requirement: word1 word2 word3 (separated by space) .Now I need word3 from each such line in the text file. Thanks in Advance, Manish (3 Replies)
Discussion started by: manish007
3 Replies

7. Shell Programming and Scripting

SOLVED: reading config file in a perl script

Hi! I have a need to do this in Perl. script.pl -config file The script would be doing a wget/LWP on a URL which is defined in the config file. So when I run the script it should return either one of these conditions - 1) OK with exit status 0. Should also print "wget URL" 2)... (6 Replies)
Discussion started by: jacki
6 Replies

8. Shell Programming and Scripting

[Solved] Problem in reading a file line by line till it reaches a white line

So, I want to read line-by-line a text file with unknown number of files.... So: a=1 b=1 while ; do b=`sed -n '$ap' test` a=`expr $a + 1` $here do something with b etc done the problem is that sed does not seem to recognise the $a, even when trying sed -n ' $a p' So, I cannot read... (3 Replies)
Discussion started by: hakermania
3 Replies

9. Shell Programming and Scripting

Reading a file by using particular word.

hi, I have a doubt in reading a file by using particular word. My requirement is that, i have one file and from that file, when ever i found "alter", that whole line i have to take it and send it to SQL Prompt. My file looks like below. Enter value for schema_nmae: QAEVO_B1 old 1:... (2 Replies)
Discussion started by: sridhusha
2 Replies

10. Shell Programming and Scripting

Can a shell script pull the first word (or nth word) off each line of a text file?

Greetings. I am struggling with a shell script to make my life simpler, with a number of practical ways in which it could be used. I want to take a standard text file, and pull the 'n'th word from each line such as the first word from a text file. I'm struggling to see how each line can be... (5 Replies)
Discussion started by: tricky
5 Replies
Login or Register to Ask a Question