cat and loop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting cat and loop
# 8  
Old 04-07-2008
Thanks everyone.

I should have mentioned that why I used head first.
The list contained number of lines for easy reading.

So in actual case, I of course have to remove head
# 9  
Old 04-07-2008
Quote:
Originally Posted by soemac
Thanks everyone.

I should have mentioned that why I used head first.
The list contained number of lines for easy reading.

So in actual case, I of course have to remove head
You didn't provide the head line, however "head -1" is Useless Use of head when you use awk.
Code:
awk '{if(NR>1)if($1=="wget")print $0"\47\nsleept 5"}' list.txt > out.txt


Last edited by danmero; 04-07-2008 at 01:23 PM.. Reason: Add ending single quote
# 10  
Old 04-07-2008
MySQL

file.txt
Code:
wget -q -O - 'http://test.com:15100/cgi-bin/search'
wget -q -O - 'http://zzzz1'
wget -q -O - 'http://zzzz11'
wget -q -O - 'http://zzzz111'
wget -q -O - 'http://zzzz1111'
wget -q -O - 'http://zzzz11111'
wget -q -O - 'http://zzzz111111'
wget -q -O - 'http://zzzz1111111'
wget -q -O - 'http://zzzz11111111'
wget -q -O - 'http://zzzz111111111'
wget -q -O - 'http://zzzz1111111111'
wget -q -O - 'http://zzzz11111111111'

Code:
#!/bin/ksh

file=file.txt
out=out.txt

rm -f out.txt

list=$(cat $file | head -1 | sed -e 's/ /+++/g')

for i in $list
do
        res=$(echo $i | sed -e 's/+++/ /g')
        echo $res >> $out
        echo sleep 5 >> $out
done

cat $out

Code:
./soemac
wget -q -O - 'http://test.com:15100/cgi-bin/search'
sleep 5

Or use your code:
Code:
out=out.txt
for f in `cat list.txt | head -1 | sed -e 's/ /+++/g'`; do
	
	echo $f | sed -e 's/+++/ /g' >> $out
	echo "sleep 5" >> $out
done


Last edited by V3l0; 04-07-2008 at 12:48 PM..
# 11  
Old 04-07-2008
The cat and the backticks are Useless. Also there is nothing ksh-specific in there, so might as well use plain sh. Proper quoting of the argument would save you from all the sed trickery. But in the end all you really need is

Code:
sed 'a\
sleep 5' file.txt

This is completely equivalent to the awk solution somebody posted earlier, albeit perhaps a little bit less readable (also known as "more succinct").
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Issue with cat command on a for loop

Good day to all, I'd like to ask for your advice with regards to this. Scenario : I have here a file named TEST.tmp wherein the value inside is below; "ONE|TWO|FIVE|THREE|FOUR|SIX~SEVEN~EIGHT" "NINE" But when I'm trying to use this in a simple command like; for TESTING in $(cat... (4 Replies)
Discussion started by: asdfghjkl
4 Replies

2. Shell Programming and Scripting

Problem while displaying(cat) file content inside telnet loop .

Hi Team, Not getting the file output inside my email which i am sending from unix box. . Please refer the below code : #!/bin/sh { sleep 5 echo ehlo 10.56.185.13 sleep 3 echo mail from: oraairtel@CNDBMUREAPZP02.localdomain sleep 3 echo rcpt to: saurabhtripathi@anniksystems.com... (1 Reply)
Discussion started by: tripathi1990
1 Replies

3. Shell Programming and Scripting

for loop with whole line using cat

Hi all, I need to create loop script to read full line and append a variable to each line. cat file I need the output like below 10.0.0.1,136 1 24 048800 id N4 No_Light 10.0.0.1,137 1 25 048900 id N4 No_Light 10.0.0.1,140 1 28 048c00 id N4 No_Light 10.0.0.1,262 1 38 048e80... (13 Replies)
Discussion started by: ranjancom2000
13 Replies

4. Shell Programming and Scripting

Loop through hosts file - cat /etc/resolv.conf

Hello... I am trying to loop through my hosts file that contains 100+ servers to check or update the nameservers on them... My while loop is breaking after the first server responds... #!/bin/bash while read line; do a=( $(echo $line | tr " " "\n") ) if }" != "" ] && }" != "#" ] &&... (1 Reply)
Discussion started by: CompSCI
1 Replies

5. Shell Programming and Scripting

simple for loop/cat issue

ok.. so problem is: I have a file that reads: cat 123 1 and 2 3 and 4 5 and 6 I was using for loops to run through this information. Code: for i in `cat 123` do echo $i done shouldn't the output come as 1 and 2 (3 Replies)
Discussion started by: foal_11
3 Replies

6. Shell Programming and Scripting

cat in the command line doesn't match cat in the script

Hello, So I sorted my file as I was supposed to: sort -n -r -k 2 -k 1 file1 | uniq > file2 and when I wrote > cat file2 in the command line, I got what I was expecting, but in the script itself ... sort -n -r -k 2 -k 1 averages | uniq > temp cat file2 It wrote a whole... (21 Replies)
Discussion started by: shira
21 Replies

7. 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

8. UNIX for Dummies Questions & Answers

Difference between cat , cat > , cat >> and touch !!!

Hi Can anybody tell the difference between Difference between cat , cat > , cat >> and touch command in UNIX? Thanks (6 Replies)
Discussion started by: skyineyes
6 Replies

9. UNIX for Dummies Questions & Answers

Using cat command in a for loop

If I have a data file containing entries like-> abc abc:123 and I use a for loop: for I in `cat data-file` do echo $I done the output would contain 2 lines -> abc.... and abc:123 but I want it to be on only one line. How can I do this? thanks (1 Reply)
Discussion started by: sleepster
1 Replies
Login or Register to Ask a Question