Visit Our UNIX and Linux User Community


unix grep


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting unix grep
# 1  
Old 09-08-2009
Computer unix grep

Hola, solicito ayuda para procesar un archivo de texto como el siguiente y luego obtener las variables.

archivo.txt:

Sending 5, 100-byte ICMP Echos to 10.249.98.94, timeout is 2 seconds:
Success rate is 100 percent (5/5), round-trip min/avg/max = 28/33/44 ms

Variables a obtener:

VAR1=10.249.98.94
VAR2=28
VAR3=33
VAR4=44


Muchas gracias de antemano.
# 2  
Old 09-08-2009

En inglÚs, por favor.

Code:
file=archivo.txt
{
 read a b c d e f g h
 IFS='=' read a b c
} < "$file"
VAR1=${g%,}
set -- $b
var=$1
IFS=/ read VAR2 VAR3 VAR4 <<.
$var
.


Last edited by cfajohnson; 09-08-2009 at 03:47 PM..
# 3  
Old 09-08-2009
Hello.

Per our forum rules, all posts must be in English.

We do provide translation services for posts from English to a number of languages as a benefit to users. However, posts must be in English.

Please repost in English.

Thank you for your cooperation.

The UNIX and Linux Forums.
# 4  
Old 09-08-2009
sorry.
HI, need some help to proccess a textfile like this and then to obtain the variables:

textfile.txt
----------
Sending 5, 100-byte ICMP Echos to 10.249.98.94, timeout is 2 seconds:
Success rate is 100 percent (5/5), round-trip min/avg/max = 28/33/44 ms

Variables to obtain:
-------------------

VAR1=10.249.98.94
VAR2=28
VAR3=33
VAR4=44


Thanks.

---------- Post updated at 04:28 PM ---------- Previous update was at 03:45 PM ----------

Quote:
Originally Posted by cfajohnson
En inglÚs, por favor.

Code:
file=archivo.txt
{
 read a b c d e f g h
 IFS='=' read a b c
} < "$file"
VAR1=${g%,}
set -- $b
var=$1
IFS=/ read VAR2 VAR3 VAR4 <<.
$var
.

Thanks but i need to obtain 4 variables from the textfile
VAR1= 10.249.98.94 <--- the ip address
VAR2= 28 <--- min time in ms
VAR3= 33 <--- avg time in ms
VAR4= 44 <--- max time in ms

... or i dont understand u
# 5  
Old 09-08-2009
Quote:
Originally Posted by mmunarriz
Thanks but i need to obtain 4 variables from the textfile
VAR1= 10.249.98.94 <--- the ip address
VAR2= 28 <--- min time in ms
VAR3= 33 <--- avg time in ms
VAR4= 44 <--- max time in ms

... or i dont understand u

That's what the script I posted does. Did you try it?

Add this line to see the results:

Code:
printf "%s\n" "VAR1=$VAR1" "VAR2=$VAR2" "VAR3=$VAR3" "VAR4=$VAR4"

# 6  
Old 09-08-2009
Quote:
Originally Posted by cfajohnson

That's what the script I posted does. Did you try it?

Add this line to see the results:

Code:
printf "%s\n" "VAR1=$VAR1" "VAR2=$VAR2" "VAR3=$VAR3" "VAR4=$VAR4"

Great! It is just that I need.
Thank u very much cfajohnson

Previous Thread | Next Thread
Test Your Knowledge in Computers #242
Difficulty: Easy
In September 1984 work was completed on restructuring the ARPANET giving U.S. military sites their own Military Network (MILNET) for unclassified defense department communications.
True or False?

10 More Discussions You Might Find Interesting

1. Web Development

JavaScript code - UNIX grep?

Hi I am new to JavaScript & haven't done much work with it, but have mainly experience with UNIX. I have a piece of code where I want to grep (excuse the UNIX language :D) for a id and get the number from that. { "time": 900, "avail": 1, "price": 0, "datetime":... (8 Replies)
Discussion started by: simpsa27
8 Replies

2. Shell Programming and Scripting

Help on grep syntax in UNIX

Dear Team /app/Appln/logs/ echo Session used server are 'grep -i pid|grep -i session | cut -d'.' -f1 | awk '{print $9}' | sort | uniq' Output - lxserver01 lxserver02 lxserver03 When I grep session pid in logs server details I can see above distinct server details but I... (6 Replies)
Discussion started by: skp
6 Replies

3. Shell Programming and Scripting

UNIX question on grep

Dear Sir, I need to remove the word /klp/ in all the files present in the directories can you tell me how to remove the word globally. grep "/klp/" * -exec ls -l Once the above command is exectubed I could see lot of files displayed. (8 Replies)
Discussion started by: ramkumar15
8 Replies

4. UNIX for Dummies Questions & Answers

Help using Grep with Unix

Hey there, I'm brand new to using Unix as I just started a course on it in my University, and I currently working through a worksheet which focuses on the many commands and methods of GREP (I'm working through the terminal command line in Unix). Currently I am confused with using Grep and vi in the... (1 Reply)
Discussion started by: SilvarHawke
1 Replies

5. Homework & Coursework Questions

finding pattern without grep in unix

how can i find related pattern in a text file without using grep command in unix (2 Replies)
Discussion started by: feint
2 Replies

6. UNIX for Dummies Questions & Answers

| help | unix | grep (GNU grep) 2.5.1 | advanced regex syntax

Hello, I'm working on unix with grep (GNU grep) 2.5.1. I'm going through some of the newer regex syntax using Regular Expression Reference - Advanced Syntax a guide. ls -aLl /bin | grep "\(x\)" Which works, just highlights 'x' where ever, when ever. I'm trying to to get (?:) to work but... (4 Replies)
Discussion started by: MykC
4 Replies

7. UNIX for Dummies Questions & Answers

| help | unix | grep - Can I use grep to return a string with exactly n matches?

Hello, I looking to use grep to return a string with exactly n matches. I'm building off this: ls -aLl /bin | grep '^.\{9\}x' | tr -s ' ' -rwxr-xr-x 1 root root 632816 Nov 25 2008 vi -rwxr-xr-x 1 root root 632816 Nov 25 2008 view -rwxr-xr-x 1 root root 16008 May 25 2008... (7 Replies)
Discussion started by: MykC
7 Replies

8. UNIX for Dummies Questions & Answers

Using Grep within a UNIX Script

Hi, I'm trying to save the wc from a grep command in my unix script and then later in my script I try to reference the variable but I have no luck. Any help is greatly appreciated! -------------------- set xTest = 'grep -i lisa daily.log' if ; then echo "TEST" >> daily.log fi... (6 Replies)
Discussion started by: lisa_0801
6 Replies

9. Shell Programming and Scripting

unix grep command

I need to seach all strings that matches "if ; then" in all files If i put grep "if ; then" *.* it is not giving any result (1 Reply)
Discussion started by: pmsuper
1 Replies

10. UNIX for Dummies Questions & Answers

Unix Shareware with the -B and -A grep fuctionality

Hi, Can anyone help me or tell me how I can get a unix shareware that will allow me use grep with the following flags -A and -B. the version of Unix we have dont have this. I am doing a grep on a log to capture any error but I want what is returend to be more meaningful. Thanks Amen. (7 Replies)
Discussion started by: aasemota
7 Replies

Featured Tech Videos