executing a command for each line in a file.

executing a command for each line in a file.

Post by JizzMcCu » Fri, 18 May 2001 23:52:46



I have a file named p
with something like

file1.html
file2.html
file3.html

At the end of my script I need to open the file in a bash script and execute
a mv command for each line.
I though about using awk

awk '{print $1;}' p - prints each line in the file
but i need to execute a command like

mv $1 $1.bak

any help (or alternative ways) of doing it would be helpful.

Cheers
Adam

 
 
 

executing a command for each line in a file.

Post by Kurt J. Lanz » Sat, 19 May 2001 00:04:00



>I have a file named p
>with something like

>file1.html
>file2.html
>file3.html

>At the end of my script I need to open the file in a bash script and
execute
>a mv command for each line.
>I though about using awk

>awk '{print $1;}' p - prints each line in the file
>but i need to execute a command like

>mv $1 $1.bak

>any help (or alternative ways) of doing it would be helpful.

Read the man page for your shell and learn about the "while" and "read"
commands, and I/O redirection.... Awwww, hell, learn how to write scripts.
Buy a book.

- Show quoted text -


 
 
 

executing a command for each line in a file.

Post by Chris F.A. Johnso » Sat, 19 May 2001 05:09:55



> I have a file named p
> with something like

> file1.html
> file2.html
> file3.html

> At the end of my script I need to open the file in a bash script and execute
> a mv command for each line.
> I though about using awk

> awk '{print $1;}' p - prints each line in the file
> but i need to execute a command like

> mv $1 $1.bak

> any help (or alternative ways) of doing it would be helpful.

while read file
do
        mv $file $file.bak
done < p

--

        =================================================================


 
 
 

1. bourne shell FOR loop - executing a command on each line in a file

I'm trying to execute a command for each line in a file.  I'm trying to use
the for loop, but it won't work on multi-word items.  I think awk might
work for my situation, but I've never used it before.  Is there a way
I can get this for loop to work (perhaps by formatting the input file)?

-------------
#!/bin/sh

if [ ! -f shows ] ; then
  echo "shows file not found"
  exit 1
fi

for SHOW in `cat shows`
do
  echo "Recording" $SHOW
# tvsched -n $SHOW -q
done
----------

shows file contains
----------
samurai jack
scrubs
joe millionaire
-----------

So I want to execute
tvsched -n "samurai jack" -q
tvsched -n "scrubs" -q
tvsched -n "joe millionaire" -q

Thanks for your help

2. Timeout too long if no network

3. RE : DIFFICULT: Can't execute system command from FVWM, but can from the command line

4. Help to Install Network Drivers

5. HELP -- execute some scripts from the command line as a command??????

6. Multiple SCSI controllers (Adaptec)

7. Batch Files: Why is it the only the last line of the batch files is executing?

8. embedded OSS sound driver

9. sh command in text file, execute it when the file is displayed?

10. Vi command to insert at the begin of a line for lines in a file

11. execute windows merge from unix command line

12. executing linux command line utilities in sequence

13. Command line command from text file