LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-05-2011, 09:25 AM   #1
sandeep_hello
Member
 
Registered: Feb 2008
Posts: 62

Rep: Reputation: 1
Need suggestion for shell script


I am creating a script. So in that when i am running a command and it giving the output like that

1
2
3
4
5
6
7

So i want to put this value after the value of “1”

1 1
1 2
1 3
1 4
1 5
1 6
1 7

Value “1” also increase as the output of grep command increase. So please suggest.


Regards
Sandeep Sharma
 
Old 10-05-2011, 10:02 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Please, can you explain what is the purpose of this script? You mentioned the grep command, but what is the role of grep in this situation? Where is it?
 
Old 10-05-2011, 10:03 AM   #3
lithos
Senior Member
 
Registered: Jan 2010
Location: SI : 45.9531, 15.4894
Distribution: CentOS, OpenNA/Trustix, testing desktop openSuse 12.1 /Cinnamon/KDE4.8
Posts: 1,144

Rep: Reputation: 217Reputation: 217Reputation: 217
this seems like your 'homework' to do ...

you will need to count how many lines columns is there
1
2
3
4
5
6
7

is 7 lines.

and now you have to do the loop 7 times printing out the output "for i"


it could look like this:

1. count how many lines/columns ( linesno=7 )
2. define i=1
Code:
while i <= linesno
do
    n=1
       while n <= linesno
       do
       print $i, " " , $n      (1.st time run i=1, n=1, giving otput like: 1 1 )
       n+1                      (now n becomes 2 which is still less than or not equal to linesno=7)
       done
i+1               ( now i gets 2)
done
is this what you are looking for ?

P.S. THIS is not really the script code and it will not work on any system if you run it, thus it needs the language structure if the script is meant for shell or PERL or ...

Last edited by lithos; 10-05-2011 at 10:06 AM.
 
Old 10-05-2011, 04:39 PM   #4
CTM
Member
 
Registered: Apr 2004
Distribution: Slackware
Posts: 308

Rep: Reputation: 287Reputation: 287Reputation: 287
You made an obtuse reference to grep, but I'm not sure how that relates to your question. If you're trying to manipulate the standard output from a command, use sed:

Code:
seq 1 7 | sed -e 's/^/1 /'
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Script running in another shell script and then exit dreamervlk Linux - General 3 09-16-2011 06:40 AM
Executing a Shell script with 654 permissions inside another shell script. changusee2k Linux - Newbie 2 06-07-2011 07:58 PM
pass variable from one shell script into another shell script xskycamefalling Programming 9 10-03-2009 01:45 AM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:24 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration