How to concatenate this simple line in Unix?

 
Thread Tools Search this Thread
Special Forums UNIX and Linux Applications Infrastructure Monitoring How to concatenate this simple line in Unix?
# 8  
Old 06-30-2010
Thanks for everything. I was able to create every single file for each snmp I have to run. Twelve files; but works great! All I have to do now its doing the "dal1 227" and done!...

What I was trying to do the same thing but in a shell function; but couldnt.
No idea how to do it. I create a file for test named "sn.sh" and inside the file
I wrote the following code:

sn()
{
snmpget -c DreamTeam dal2-hr1 ifAlias.$1
}

But I have no idea how to call it and run it or if there's something wrong or missing. Can anyone help? Thanks!!
# 9  
Old 06-30-2010

To load the functions, source the file with:
Code:
. sn.sh

# 10  
Old 06-30-2010
Ok, and where did I put the variable $1. This variable its a numeric name; Could be any number between 1-1000?

I tried:

. sn.sh 227 -> No output is given
. sn 227.sh -> Error

Last edited by javygonx; 06-30-2010 at 03:38 AM..
# 11  
Old 06-30-2010

Load the functions then call them:
Code:
. sn.sh
sn 227

# 12  
Old 06-30-2010
I got it. Thanks. I did the function and for some reason when I ran it it doesnt like it. It says "Too Many Arguments".... But when I did the script named "sn" and inside the file I wrote "snmpget -c DreamTeam ifAlias.$1". All I have to do to run its is "sn 227" and works.

But on the function it doesnt.
# 13  
Old 06-30-2010
Quote:
Originally Posted by javygonx
I got it. Thanks. I did the function and for some reason when I ran it it doesnt like it. It says "Too Many Arguments".... But when I did the script named "sn" and inside the file I wrote "snmpget -c DreamTeam ifAlias.$1". All I have to do to run its is "sn 227" and works.

But on the function it doesnt.

How is the function defined? What is in it?

How did you call the script? the function?

Please post the exact code you used.
# 14  
Old 07-01-2010
Ok. Name of the function file "sn.sh"

Code in the file "sn.sh":
##################
sn()
{
snmpget -c DreamTeam dal2-hr1 ifAlias.$1
}
##################

To call function: . sn.sh [ENTER]

To run it: "sn 227" [ENTER]
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with concatenate multiple line into one line

Hi, Do anybody experience how to concatenate multiple line into one line by using awk or perl command? Input file: >set1 QAWEQRQ@EWQEASED ASDAEQW QAWEQRQTQ ASRFQWRGWQ From the above Input file, it got 5 lines Desired output file: >set1... (6 Replies)
Discussion started by: perl_beginner
6 Replies

2. Shell Programming and Scripting

Concatenate small line with next line perl script

Hello to all, I'm new to perl, I have input file that contains the string below: 315350535ff450000014534130101ff4500ff45453779ff450ff45545f01ff45ff453245341ff4500000545000This string has as line separator "ff45". So, I want to print each line but the code below is not working. perl -pe '... (2 Replies)
Discussion started by: Ophiuchus
2 Replies

3. Shell Programming and Scripting

awk concatenate every line of a file in a single line

I have several hundreds of tiny files which need to be concatenated into one single line and all those in a single file. Some files have several blank lines. Tried to use this script but failed on it. awk 'END { print r } r && !/^/ { print FILENAME, r; r = "" }{ r = r ? r $0 : $0 }' *.txt... (8 Replies)
Discussion started by: sdf
8 Replies

4. Shell Programming and Scripting

Logfile - extracting certain lines to concatenate into 1 line

I've got a log file from automatic diagnostic runs. The log file is appended to each time an automatic log is run. I'd like to just pull certain lines from each run in the log file, and concatenate them into 1 comma delimited line (for export into excel or an html table). Each diagnostic run... (3 Replies)
Discussion started by: BecTech
3 Replies

5. Shell Programming and Scripting

Concatenate strings line by line

Hi, I have a noob question . Can someone help me how to concatenate line by line using this variables? var1: Apple| Banana| var2: Red Yellow then how can I concatenate both line by line? in which the result would be: Apple|Red Banana|Yellow just to generate a row result i was... (6 Replies)
Discussion started by: hagdanan
6 Replies

6. UNIX for Advanced & Expert Users

need to concatenate two lines if the line doesnt end with quotes

Hi I am getting a source file where the columns are seperated by comma and double Quotes Eg1 : "AAA","BBB","CCCC" in the same source file i am also getting few lines where my last columns double quotes are ending in its next line or the next next line Eg2: "AAA","BBB","CCC CC"... (9 Replies)
Discussion started by: laxmi131
9 Replies

7. Shell Programming and Scripting

concatenate all duplicate line in a file.

Hi All, i have a zip file like the format 794051400123|COM|24|0|BD|R|99.98 794051413727|COM|11|0|BD|R|28.99 794051415622|COM|23|0|BD|R|28.99 883929004676|COM|0|0|BD|R|28.99 794051400123|MOM|62|0|BD|R|99.98 794051413727|MOM|4|0|BD|R|28.99 794051415622|MOM|80|0|BD|R|28.99 ... (30 Replies)
Discussion started by: vaskarbasak
30 Replies

8. Shell Programming and Scripting

concatenate and display 2 lines as 1 with a condition for 2 line ?

I have 2 pattern of lines (SQL query and Time taken)in a log i need to capture all SQL queries with time taken >20 sec and need to display as one line. 2 lines from log: 2007-10-23 11:39:17,061 DEBUG - SQL Query : SELECT A.GROUP_CD , C.FN_CD FROM UP_GROUP A , PRD_GROUP_TO_FN B , PRD_FN... (7 Replies)
Discussion started by: vithala
7 Replies

9. UNIX for Advanced & Expert Users

Need solution concatenate and display 2 lines as 1 with a condition for 2 line ?

I have 2 pattern of lines (SQL query and Time taken)in a log i need to capture all SQL queries with time taken >20 sec and need to display as one line. 2 lines from log: 2007-10-23 11:39:17,061 DEBUG - SQL Query : SELECT A.GROUP_CD , C.FN_CD FROM UP_GROUP A , PRD_GROUP_TO_FN B , PRD_FN... (1 Reply)
Discussion started by: vithala
1 Replies

10. UNIX for Dummies Questions & Answers

how to concatenate two command in one line and get the display in one screen

Hi, I would like to know , how to concatenate two command in one line and get the display in one screen for eg command 1 : ls -l /data/logs command 2 : ls -l /data/errors output shd be /data/logs /data/errors xx-xx-xx-xx abc.log xx-xx-xx-xx... (9 Replies)
Discussion started by: vasikaran
9 Replies
Login or Register to Ask a Question