Looping and conditional branching on the command line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Looping and conditional branching on the command line
# 1  
Old 07-29-2005
Looping and conditional branching on the command line

I am piping STDOUT from commands such as ifconfig and dmesg through grep, sed and awk to get the information I need.

I need to now perform some looping and branching now and have been trying to figure out how to do this on the command line.

You may ask "Why the command line? - Why not put it into a script file?' I have a situation that the requirements put to me that I am not supposed to write any files to the system when gathering my information from the system.

Any help that you can provide or at least pointing me in the right direction would be greatly appreciated.

Thank you very much,

KG
# 2  
Old 07-29-2005
as an example of looping from the command line may looks something like this (tested with korn shell):

$ for i in `ls -1`; do file $i; done

.. this uses the file command to show you the file type for each file on the working directory...

does this answer your question?
# 3  
Old 08-01-2005
infierno - thank you for your reply...

I believe it gets me further down the road. Thank you for steering me in the right direction.

Thank you,

KG
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Looping on variable having new line \n fails

I have a for loop that constructs a variable "filelistonly" having entries separated by "\n" new line. The second, third & fourth while loops are my attempt to iterate the variable "filelistonly" upon new line "\n", however non of them work. Below is my script: //First Loop for i in... (2 Replies)
Discussion started by: mohtashims
2 Replies

2. Shell Programming and Scripting

sed conditional \n replace for each line

How could be removed \n only if appearing at position 80 in the line? (4 Replies)
Discussion started by: RomanF
4 Replies

3. Shell Programming and Scripting

Process Detection and Conditional Branching . . .

Greetings! First post for this newbie :) If anyone has a moment to spare, I have a quick question for the community. For the record, I'm running Xubuntu 12.04... Based on a few hours' digging about, I've created an executable test script, "test.sh" which incorporates the following code: ... (7 Replies)
Discussion started by: LinQ
7 Replies

4. Shell Programming and Scripting

Conditional Looping In Files

I have a req. where i need to read data from multiple files and take counts of row which satisfy the condition. e.g.: FILE1: Col1 Col2 Col3 12 ab cd 15 de fg 25 gh tm FILE2: Col1 Col2 Col3 21 ab1 cd1 13 de1 fg1 25 gh1 tm1 --- --- FILE-N... i need to find the count of rows... (6 Replies)
Discussion started by: kunal007
6 Replies

5. Shell Programming and Scripting

conditional append one line in file.

Hi, Unix gurus, I have a requirement as following: checking existing file, if the file only contain one line. then append "No data" else keep existing file as is. can i achieve this by in command line without write a script. :wall: Thanks in advance. (4 Replies)
Discussion started by: ken002
4 Replies

6. Shell Programming and Scripting

Conditional Multi-Line Grep Problem

Hi, I have a very large file I want to extract lines from. I'm hoping Grep can do the job, but I'm running into problems. I want to return all lines that match a pattern. However, if the following line of a matched line contains the word "Raw" I want to return that line as well. Is this... (3 Replies)
Discussion started by: redbluefish
3 Replies

7. Shell Programming and Scripting

Conditional removing of words from a line

Hi , I have a .csv file,from which I want to remove some data from each column as below. Source Data GT_12_AUDIT,SCHEDULED,NOZOMI2010/GT_12_AUDIT,CTSCAN/Zh_GT_6547887/GT_12_AUDIT,CTSCAN/Zh_GT_6547887... (3 Replies)
Discussion started by: gaur.deepti
3 Replies

8. Shell Programming and Scripting

HELP Need in SED/PERL conditional line replacement

Hi , I need some help on perl/sed conditional replacement The situation is like below . I have a file contents like below . AAA|BBB|CCC|DDD AAA|BCF|CCC|HHH AAA|BVF|JJJ|KKK Here in the above file . I know my second column value (taking "|" as my delimited ) Basically I have to... (3 Replies)
Discussion started by: robin.r888
3 Replies

9. Shell Programming and Scripting

Conditional reverse of certain file line order

Hi I am brand new to programming, I dont know how to go about this task, or what language is best for this...If there is an easy solution in different languages, I would love to see them. I want to learn about the steps to take on this, so Please put in comments where code is used. I believe in... (9 Replies)
Discussion started by: perlrookie
9 Replies

10. Shell Programming and Scripting

Looping through each line of text file

Dear all, I have a text file like below. eg.txt abcd efgh ijkl mnop I need a script, which should read the text file eg.txt and assign each line as a parameter. This , i wil use further to pass it a java command to invoke. All inside a for loop Need your help on this. With... (2 Replies)
Discussion started by: KrishnaSaran
2 Replies
Login or Register to Ask a Question