Interpret a text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Interpret a text file
# 1  
Old 01-05-2010
Interpret a text file

hi

I have a text file abc.txt as below

Code:
a = 0
b = 1
c = 3

i want to interpret this file i.e. if number corresponding to 'a' is 0 i want to run a script script.bash .

How do do that?
# 2  
Old 01-05-2010

Code:
while read a b c
do
  if [ "$a" = a ] && [ "$c" = 0 ]
  then
     script.bash
  fi
done < abc.txt

# 3  
Old 01-05-2010
thanks a lot

i still have another problem in getting exactly what i want

this is how i get the file abc.txt

Code:
tail -3 file1.txt| awk '{print $5 " "  "="  " "  $NF}' > abc.txt

so when i try

Code:
while read a b c
do
if [ "$c" = 0 ] 
then 
#### do something
fi
done <abc.txt

it attaches '\r' with $c in file abc.txt i.e. 0 becomes '0\r' and so on
thus the comparison fails.

---------- Post updated at 02:41 PM ---------- Previous update was at 02:39 PM ----------

above problem occurs only when i generate abc.txt as shown above.

If i type the contents of abc.txt by myself it works fine

please advise
# 4  
Old 01-05-2010

Remove the carriage returns:
Code:
tail -3 file1.txt |
  awk '{ gsub( "\r", "", $NF)
         print $5 " "  "="  " "  $NF}' > abc.txt

# 5  
Old 01-06-2010
it helped...thanks a lot
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Match text to lines in a file, iterate backwards until text or text substring matches, print to file

hi all, trying this using shell/bash with sed/awk/grep I have two files, one containing one column, the other containing multiple columns (comma delimited). file1.txt abc12345 def12345 ghi54321 ... file2.txt abc1,text1,texta abc,text2,textb def123,text3,textc gh,text4,textd... (6 Replies)
Discussion started by: shogun1970
6 Replies

2. UNIX for Beginners Questions & Answers

Who -r interpret?

I booted into single user mode with /usr/sbin/reboot -- -s but after doing a control -d my who -r shows run-level 3 Nov 17 14:07 3 0 S I was expecting it to show run-level S why is this still in run level 3? thanks (1 Reply)
Discussion started by: goya
1 Replies

3. UNIX for Dummies Questions & Answers

Need to interpret code

hi All, i have never used sed in Unix environment, but i have one script which is using this following command: cat audit_session_rpt_MSP_20140331.lst|sed -n '/Apr 14/!p'| sed -n '/Page/!p'| sed -n '/UserName/!p' |\ egrep -v '^-|^=|^\*'|sed '/^$/d'|sed -e '1,7d'... (1 Reply)
Discussion started by: lovelysethii
1 Replies

4. Shell Programming and Scripting

don't know how to interpret this

Can anyone tell me how to interpret this: listpage="ls |more" (the spaces are there in the example) $listpage It's from my bash book and I'm not sure what it means (3 Replies)
Discussion started by: Straitsfan
3 Replies

5. UNIX for Dummies Questions & Answers

How does Awk interpret $0!~

I know $0 is the entire file's contents (at least I think that is what it is!), but what exactly is: $0!~ This was a snippet from a larger line awk '$0!~/^$/ {print $0}' This deletes blank lines, but I want to know specifically the $0!~ part... I am guessing /^$/ is regex for blank line...... (5 Replies)
Discussion started by: glev2005
5 Replies

6. Shell Programming and Scripting

Can someone interpret this -- not sure

Was wondering if someone could interpret this for me -- I'm not sure what everything means. It's a shell script from my bash book: cd () { builtin cd "$@" es=$? echo "$OLDPWD ->$PWD" return $es } what I don't quite understand is the "$@". I think, if I understand... (6 Replies)
Discussion started by: Straitsfan
6 Replies

7. UNIX for Dummies Questions & Answers

How to interpret TOP

Hi, So I am new to Unix, and I need to check the performance of some apps I am running. But I don't know how to interpret the output from TOP. Could somebody please explain the difference between the different values. And also explain how I can have a process which has a %CPU > 100? ... (7 Replies)
Discussion started by: dj_jay_smith
7 Replies

8. Shell Programming and Scripting

Can't interpret variable in if statement

Can someone help me out here. I can't get this piece of code to work. i.e. $ALL_EVENTS does not get interpreted in the if brackets. The first part is the code, the second part is the execution of the code. Note: $ALL_EVENTS does equal 2, but there is no value once passed to the if statement. ... (4 Replies)
Discussion started by: jwholey
4 Replies

9. UNIX for Dummies Questions & Answers

Please interpret.

Hi guys, I have no idea on unix but suddenly, my cobol programs calls a unix script that i know nothing about. can you guys interpret these lines for me? i know its a print command but I want to actually know how many copies it prints. qprt -da -P $1 -t '6' -i '6' -l '70' $2 qprt -da... (1 Reply)
Discussion started by: supacow
1 Replies

10. Shell Programming and Scripting

How Do We Interpret This ?

ksh $ETL_XXX/bin/filename.ksh wf_workflowname . Which is used in post session command. (2 Replies)
Discussion started by: dummy_needhelp
2 Replies
Login or Register to Ask a Question