Using cat command in a for loop


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Using cat command in a for loop
# 1  
Old 09-12-2003
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
# 2  
Old 09-12-2003
Code:
while read I
do
 echo "$I"
done < data-file

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 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. Homework & Coursework Questions

Need some help on using cat command

I have a file "sample.txt" with the content as below: Hi This is a Sample Text. I need a single command using cat which serve the following purpose. 1.display the contents of sample.txt 2.append some text to it 3. and then exit But, all should be served by a sinle... (1 Reply)
Discussion started by: ashok.g
1 Replies

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

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

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. Shell Programming and Scripting

cat and loop

Hi I have a simple code that I want to execute. out=out.txt for f in `cat list.txt | head -1`; do echo $f >> $out echo "sleep 5" >> $out done cat list.txt | head -1 wget -q -O - 'http://test.com:15100/cgi-bin/search cat out.txt wget sleep 5 -q sleep 5 -O (10 Replies)
Discussion started by: soemac
10 Replies

10. Shell Programming and Scripting

the CAT command

hi everybody, how do i open a txt file writen in unix on to a web page so when i want to view the txt file that was generated from a shell program, that file is open on a web page do i use the cat > filename.html command to do this, or is there another way many thanks :D (2 Replies)
Discussion started by: alexd
2 Replies
Login or Register to Ask a Question