list file content


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting list file content
# 1  
Old 04-27-2011
list file content

I need help. I have this file, it has 2 fields with at least 300 lines:

1 4
2 3
3 6
4 2
.
.
300 5

My output should be for every line in input file the output should be like this, for example line 1:

wget http://somewebsite/page=1&line=1
wget http://somewebsite/page=1&line=2
wget http://somewebsite/page=1&line=3
wget http://somewebsite/page=1&line=4

for line 2
wget http://somewebsite/page=2&line=1
wget http://somewebsite/page=2&line=2
wget http://somewebsite/page=2&line=3

for line 3

wget http://somewebsite/page=3&line=1
wget http://somewebsite/page=3&line=2
wget http://somewebsite/page=3&line=3
wget http://somewebsite/page=3&line=4
wget http://somewebsite/page=3&line=5
wget http://somewebsite/page=3&line=6

and so on.....

That is, the first field will become the "page" value while the second field becomes the total value of "line" for every "page".

Please help. Thank you.
# 2  
Old 04-27-2011
Code:
while read p cnt ; do 
   for i in `seq $cnt` ; do 
       echo "wget http://smthn/page=${p}&line=$i" 
   done
done < input


Last edited by mirni; 04-27-2011 at 10:40 PM..
This User Gave Thanks to mirni For This Post:
# 3  
Old 04-27-2011
Code:
kent$  echo "1 4
dquote> 2 3
dquote> 3 6
dquote> 4 2" | awk '{for(i=1;i<=$2;i++)print "http://site/page="$1"&line="i}'

http://site/page=1&line=1
http://site/page=1&line=2
http://site/page=1&line=3
http://site/page=1&line=4
http://site/page=2&line=1
http://site/page=2&line=2
http://site/page=2&line=3
http://site/page=3&line=1
http://site/page=3&line=2
http://site/page=3&line=3
http://site/page=3&line=4
http://site/page=3&line=5
http://site/page=3&line=6
http://site/page=4&line=1
http://site/page=4&line=2

# 4  
Old 04-27-2011
Code:
awk '{for (i=1;i<=$2;i++) printf "wget http://somewebsite/page=%s&line=%s\n",$1,i}' infile |sh

This User Gave Thanks to rdcwayx For This Post:
# 5  
Old 04-28-2011
this may not be very helpful if I have 1000 lines. Thanks anyway sk1418

---------- Post updated at 10:35 PM ---------- Previous update was at 10:33 PM ----------

the above comment is for sk1418. mirni and rdcwayx codes work very well.
Thank you very much
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

List the files after sorting based on file content

Hi, I have two pipe separated files as below: head -3 file1.txt "HD"|"Nov 11 2016 4:08AM"|"0000000018" "DT"|"240350264"|"56432" "DT"|"240350264"|"56432" head -3 file2.txt "HD"|"Nov 15 2016 2:18AM"|"0000000019" "DT"|"240350264"|"56432" "DT"|"240350264"|"56432" I want to list the... (6 Replies)
Discussion started by: Prasannag87
6 Replies

2. UNIX for Dummies Questions & Answers

List all File Content its subdirectory

Is there anyway to display the file content in a subdirectory that starts or ends with a certain filename, say .txt? or start with NTS $ ls * dos2unix.bat dos2unix.exe test.txt FilePermissions: filepermission.html NTSLA32_SystemDrive.txt NTSLA36_regedit.txt filepermission.sh ... (1 Reply)
Discussion started by: alvinoo
1 Replies

3. Shell Programming and Scripting

How to remove exisiting file content from a file and have to append new file content?

hi all, i had the below script x=`cat input.txt |wc -1` awk 'NR>1 && NR<'$x' ' input.txt > output.txt by using above script i am able to remove the head and tail part from the input file and able to append the output to the output.txt but if i run it for second time the output is... (2 Replies)
Discussion started by: hemanthsaikumar
2 Replies

4. Shell Programming and Scripting

Sed: replace content from file with the content from file

Hi, I am having trouble while using 'sed' with reading files. Please help. I have 3 files. File A, file B and file C. I want to find content of file B in file A and replace it by content in file C. Thanks a lot!! Here is a sample of my question. e.g. (file A: a.txt; file B: b.txt; file... (3 Replies)
Discussion started by: dirkaulo
3 Replies

5. Shell Programming and Scripting

How to list the content of a directory

Hi I want to write a script that reads a directory name, checks if the directory exists and lists the content of that directory. That's what I have at the moment. function listDirectory { echo "Give in a directory name" read name #Here I want to check if the... (4 Replies)
Discussion started by: hss
4 Replies

6. Shell Programming and Scripting

Replacing content from a list

Okay, so I am not quite sure the best way of going about this. I have a whole stack of files that need items replaced with a code corresponding to it. In particular, I am looking to replace the names of countries with the two letter iso country code. The files themselves are in csv format with... (4 Replies)
Discussion started by: johnlee
4 Replies

7. UNIX for Dummies Questions & Answers

How to list content with file name ?

I want to search the string including the symbol like 'search' for example, file a.txt in \\dir contains, a for 'appable' b for 'banana' c for 'cat' s for 'search' Here I need to display(serach outpur) like \\dir\a.txt s for 'search' ... ... How to list content with file name... (5 Replies)
Discussion started by: gkskumar
5 Replies

8. Shell Programming and Scripting

list file content as individual variables

Hello, I've created a couple of files within a list using the command "ls -ltr | tail -2 > list" These files are the newest files placed within a directory. From the "list" file, I need to place the filenames as a variable. In which the newest file will be called "new_ctrl" the older file... (4 Replies)
Discussion started by: petersf
4 Replies

9. Shell Programming and Scripting

Need help with awk - how to read a content of a file from every file from file list

Hi Experts. I need to list the file and the filename comes from the file ListOfFile.txt. Basicly I have a filename "ListOfFile.txt" and it contain Example of ListOfFile.txt /home/Dave/Program/Tran1.P /home/Dave/Program/Tran2.P /home/Dave/Program/Tran3.P /home/Dave/Program/Tran4.P... (7 Replies)
Discussion started by: tanit
7 Replies

10. AIX

find for specific content in file in the directory and list only file names

Hi, I am trying to find the content of file using grep and find command and list only the file names but i am getting entire file list of files in the directory find . -exec grep "test" {} \; -ls Can anyone of you correct this (2 Replies)
Discussion started by: madhu_Jagarapu
2 Replies
Login or Register to Ask a Question