cat vs head vs readline get variable from txt file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting cat vs head vs readline get variable from txt file
# 1  
Old 04-15-2009
cat vs head vs readline get variable from txt file

I have a file with a single filename in it, which I want to assign to a BASH variable, so I've been trying:

c=$(head -1 somefile)
echo $c

which outputs correctly, but them when I do

...
somecommand $c

it says it can't find the file, is that because it's grabbing the whole line, and how should I be doing it different, grep maybe?
# 2  
Old 04-15-2009
whats that somecommand?? and is that file available on the dir where you are running that script??
# 3  
Old 04-15-2009
Code:
#!/bin/bash
c=$(head -1 toconvertfile)
ffmpeg -i $c -an -pass 1 -vcodec libx264 -vpre fastfirstpass -b 512000 -bt 512000 -threads 0 -s 600x400 -r 30 -f flv $c.tempfile
ffmpeg -i $c -acodec libfaac -ab 64k -pass 2 -vcodec libx264 -vpre hq -b 512000 -bt 512000 -threads 0 -s 600x400 -r 30 -f flv $c.flv
rm $c.tempfile
ffmpeg -i $c.flv -s 174x116 -an -ss 5 -vframes 1 -f image2 -y $c.flv.jpg

#: cat toconvertfile
test1.avi

#: ls test1.*
test1.avi

if I just use

Code:
#!/bin/bash
ffmpeg -i $1 -an -pass 1 -vcodec libx264 -vpre fastfirstpass -b 512000 -bt 512000 -threads 0 -s 600x400 -r 30 -f flv $1.tempfile
ffmpeg -i $1 -acodec libfaac -ab 64k -pass 2 -vcodec libx264 -vpre hq -b 512000 -bt 512000 -threads 0 -s 600x400 -r 30 -f flv $1.flv
rm $1.tempfile
ffmpeg -i $1.flv -s 174x116 -an -ss 5 -vframes 1 -f image2 -y $1.flv.jpg

with

#: ./conv.sh test1.avi

it works
# 4  
Old 04-15-2009
can you post the out put of
Code:
cat -vet toconvertfile
c=$(head -1 toconvertfile)
echo "$c"|cat -vet
echo "$c"

# 5  
Old 04-15-2009
Code:
# cat -vet toconvertfile
test1.avi$
# c=$(head -1 toconvertfile)
# echo "$c"|cat -vet
test1.avi$
t# echo "$c"
test1.avi

# 6  
Old 04-16-2009
okay, well I got it to work, thanks for the help, the final code is this:

Code:

#!/bin/bash
while [ 1 = 1 ]
 do
    c=$(head -1 toconvertfile)
  for i in $c
    do
      ffmpeg -i $c -an -pass 1 -vcodec libx264 -vpre fastfirstpass -b 512000 -bt 512000 -threads 0 -s 600x400 -r 30 -f flv $c.tempfile
      ffmpeg -i $c -acodec libfaac -ab 64k -pass 2 -vcodec libx264 -vpre hq -b 512000 -bt 512000 -threads 0 -s 600x400 -r 30 -f flv $c.flv
      ffmpeg -i $c.flv -s 174x116 -an -ss 5 -vframes 1 -f image2 -y $c.flv.jpg
      rm $c.tempfile
      cat /dev/null > toconvertfile
      done
sleep 30
done


Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash - Trying to cat a file that is a variable

Thank you in advance for looking at this, I've scoured the internet and can't find the answer I'm looking for!! - I am new at bash script so please bare with me!! I have a script where I've identified individual files within a folder, the filename is then stored as a variable ($filename):... (3 Replies)
Discussion started by: paperbackwriter
3 Replies

2. Shell Programming and Scripting

Cannot open txt file in UNIX using cat utility

Hi, I am not being able to open txt files with 'cat'. One thing to mention is, the filenames start with #. I guess one can have a unix filename that starts with a special/wildcard character. I have filenames starting with @ and they are opening perfectly with cat. (5 Replies)
Discussion started by: Subhasis
5 Replies

3. Shell Programming and Scripting

assigning variable in txt file

Hi all, One of my txt file has common format like . And I need to manually assign variable to "/a/b/c/file1/txt" , which has common text before "Calculated summary file:". I wonder if I can use some command to do that for me, that it read the file and check for that comonn text and assign... (2 Replies)
Discussion started by: emily
2 Replies

4. Shell Programming and Scripting

cat file with variable substitution

MyFile contains: ALTER TABLE $DBN.$TBN ADD $COL $TYP COMPRESS ($VAL); I need to cat the file and have it substitute all of the variables with their contents. cat MyFile does not work. The following works for the first line, but errors on the second line because of the paren: $ while read... (2 Replies)
Discussion started by: Phil27577
2 Replies

5. Shell Programming and Scripting

Help awking a 'head -1 file.txt' input

Hi there, my ksh script collects a procstack trace for a particular pid and then greps it by a transaction id to find out the pthread ID: ---------- tid# 1876087 (pthread ID: 4466) ---------- So the pthread ID I want is 4466 in this case, and it is assighed to the variable $pthread.... (4 Replies)
Discussion started by: tmf33uk
4 Replies

6. Shell Programming and Scripting

for i in `cat myname.txt` && for y in `cat yourname.txt`

cat myname.txt John Doe I John Doe II John Doe III ----------------------------------------------------------------------- for i in `cat myname.txt` do echo This is my name: $i >> thi.is.my.name.txt done ----------------------------------------------------------------------- cat... (1 Reply)
Discussion started by: danimad
1 Replies

7. UNIX for Dummies Questions & Answers

Using a variable inside a file to cat another.

I have a question to do and it's somewhat confusing. It says, and I quote "Create a file called file_1 with three lines of text in it. Create a shell variable called "f_name", assign it the string "file_1". Use the cat command and the variable "f_name" to display the contents of the file... (3 Replies)
Discussion started by: MaestroRage
3 Replies

8. UNIX for Dummies Questions & Answers

grep/cat/more -- search in a txt file and display content from a specific "keyword"

Hi, I have a .txt file Sample: ===================== NEXT HOST ===================== AEADBAS001 ip access-list extended BLA_Incoming_Filter ip access-list extended BLA_Outgoing_Filter access-list 1 permit xxxxxxxxxxxxxx access-list 2 permit xxxxxxxxxxxxxx =====================... (4 Replies)
Discussion started by: I-1
4 Replies

9. Shell Programming and Scripting

variable= 'cat file|wc -l' String problems

Hi, does anybody knows about wc -l, how to transform it inot a just number? this script ALWAYS executes the command3!!, However, the value of BMU_RUNNING is 1 case $BMU_RUNNING in *0) command1 ;; *1) command 2;; *)command 3;; esac The... (3 Replies)
Discussion started by: Santiago
3 Replies
Login or Register to Ask a Question