Help with cut and tail


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with cut and tail
# 8  
Old 12-23-2009
Quote:
Originally Posted by nogame11
can anybody tell me why is code does not work ??



it never enter's the if even when the name is right

Code:
echo "Name:"
read Name

prev=`cut -d ";" -f1-3 funcionarios.cvs`

for linha in "$prev"
do
     fun=`echo "$linha" | cut -d ";" -f2`
     if [ "$Nome" = "fun" ]; then
          echo "It's the same"
     fi
done

What is Nome in your if-statement?

If that should be Name, you should perhaps proof-read your code before asking.
# 9  
Old 12-24-2009
Sorry it's $Name

---------- Post updated at 03:06 PM ---------- Previous update was at 03:05 PM ----------

But that's not the problem
# 10  
Old 12-24-2009
fun is a variable, so...

Code:
if [ "$Name" = "$fun" ];

Also try using set -x in your script to debug it.
# 11  
Old 12-24-2009
yes
ok
# 12  
Old 12-24-2009
Code:
if [ "$Name" = "$fun" ]; then

But the rest of the code does not do what you expect it to do. You can see what happens by using echo statements with the variable names.
The preferred method for this type of operation is something like this:
Code:
echo "Name:"
read $input_name
while IFS=";" read code name location
do 
  if [ "$input_name" = "$name" ]
  then
    echo $code
  fi
done < funcionarios.csv


Last edited by Scrutinizer; 12-24-2009 at 05:26 PM..
# 13  
Old 12-24-2009
It does but what I don't get is why $Name and $fun have the same value but the if does not work

the file funcionarios.csv has this

001op;Jose Antonio Borges;Rua de Cima, 7, Lisboa
002op;Silvia Maria;xxxx xxxx, 8, Lisboa
003op;XXXXX ZZZZ;aaaaaa ddd, 9, Lisboa
# 14  
Old 12-24-2009
Because "$Name" != "Jose Antonio Borges Silvia Maria XXXXX ZZZZ"
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using :<<cut / cut to comment out block of bash script

I am using : << cut / cut to comment out block of code. Works fine on few lines of script, then it gives me this cryptic error when I try to comment out about 80 lines. The "warning " is at last line of script. done < results 169 echo "END read all positioning parameters" 170... (8 Replies)
Discussion started by: annacreek
8 Replies

2. UNIX for Beginners Questions & Answers

Cut command: can't make it cut fields

I'm a complete beginner in UNIX (and not a computer science student either), just undergoing a tutoring course. Trying to replicate the instructions on my own I directed output of the ls listing command (lists all files of my home directory ) to My_dir.tsv file (see the screenshot) to make use of... (9 Replies)
Discussion started by: scrutinizerix
9 Replies

3. Shell Programming and Scripting

Joining multiple files tail on tail

I have 250 files that have 16 columns each - all numbered as follows stat.1000, stat.1001, stat.1002, stat.1003....stat.1250. I would like to join all 250 of them together tail by tail as follows. For example stat.1000 a b c d e f stat.1001 g h i j k l So that my output... (2 Replies)
Discussion started by: kayak
2 Replies

4. Shell Programming and Scripting

Cut Command error cut: Bad range

Hi Can anyone what I am doing wrong while using cut command. for f in *.log do logfilename=$f Log "Log file Name: $logfilename" logfile1=`basename $logfilename .log` flength=${#logfile1} Log "file length $flength" from_length=$(($flength - 15)) Log "from... (2 Replies)
Discussion started by: dgmm
2 Replies

5. Shell Programming and Scripting

tail, grep and cut

Hello all, I have some weird problem that kinda baffles me. Say I have the following test file: claudia:~/tmp$ cat testfile.txt This is a test line This is the second test line And yeah, this is the third test line Then say I want to tail the file, grep for the word "third" then... (7 Replies)
Discussion started by: sylaan
7 Replies
Login or Register to Ask a Question